Doors Open when Starting game [Solved}

// Fill out your copyright notice in the Description page of Project Settings.

#include “BuildingEscape.h”
#include “OpenDoor.h”

// Sets default values for this component’s properties
UOpenDoor::UOpenDoor()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don’t need them.
PrimaryComponentTick.bCanEverTick = true;

// ...

}

// Called when the game starts
void UOpenDoor::BeginPlay()
{
Super::BeginPlay();
Owner = GetOwner();
ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();
}

// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

//Poll the trigger volume
if (PressurePlate->IsOverlappingActor(ActorThatOpens))
{
	OpenDoor();
	LastDoorOpenTime = GetWorld()->GetTimeSeconds();

}


if (GetWorld()->GetTimeSeconds() - LastDoorOpenTime > DoorCloseDelay)
{
	CloseDoor();
}

}

void UOpenDoor::OpenDoor()
{
//set the door rotation
Owner->SetActorRotation(FRotator(0.0f, OpenAngle, 0.0f));
}

void UOpenDoor::CloseDoor()
{
//set the door rotation
Owner->SetActorRotation(FRotator(0.0f, 0.0f, 0.0f));
}

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include “Components/ActorComponent.h”
#include “OpenDoor.generated.h”

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UOpenDoor : public UActorComponent
{
GENERATED_BODY()

public:
// Sets default values for this component’s properties
UOpenDoor();

protected:
// Called when the game starts
virtual void BeginPlay() override;

void OpenDoor();
void CloseDoor();

public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

private:
UPROPERTY(VisibleAnywhere)
float OpenAngle = -90.0f;

UPROPERTY(EditAnywhere)
	ATriggerVolume* PressurePlate; 

UPROPERTY(EditAnywhere)
	float DoorCloseDelay = 1.0f;

	float LastDoorOpenTime;

	AActor* ActorThatOpens;

	AActor* Owner;

};

What I am I doing wrong?

Edit:

I made float OpenAngle = 0.0f

and the yaw value in the close door function 90.0.

I think there is a bug when Ben copies Open door and changes it to close door, idk. But They are acting as opposites.

Is your issue that they’re acting as opposites then? Depending on the default rotation of the door in unreal it you may actually have it backwards. Try setting OpenAngle to 90.0 and the yaw and close door to 0.0.

Privacy & Terms