OpenDoor.h
#pragma once
#include “Components/ActorComponent.h”
#include “OpenDoor.generated.h”
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UOpenDoor : public UActorComponent
{
GENERATED_BODY()
public:
UOpenDoor();
virtual void BeginPlay() override;
void OpenDoor();
void CloseDoor();
virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;
private:
UPROPERTY(EditAnywhere)
float OpenAngle = 90.f;
UPROPERTY(EditAnywhere)
ATriggerVolume* PressurePlate;
UPROPERTY(EditAnywhere)
float DoorCloseDelay = 1.f;
float LastDoorOpenTime;
AActor* ActorThatOpens;
AActor* Owner;
};
OpenDoor.CPP
#include “BuildingEscape.h”
#include “OpenDoor.h”
UOpenDoor::UOpenDoor()
{
PrimaryComponentTick.bCanEverTick = true;
}
void UOpenDoor::BeginPlay()
{
Super::BeginPlay();
Owner = GetOwner();
ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();
}
void UOpenDoor::OpenDoor()
{
Owner->SetActorRotation(FRotator(0.f, OpenAngle, 0.f));
}
void UOpenDoor::CloseDoor()
{
Owner->SetActorRotation(FRotator(0.f, 0.f, 0.f));
}
void UOpenDoor::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction )
{
Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
if (PressurePlate->IsOverlappingActor(ActorThatOpens))
{
OpenDoor();
LastDoorOpenTime = GetWorld()->GetTimeSeconds();
}
if (GetWorld()->GetTimeSeconds() - LastDoorOpenTime > DoorCloseDelay)
{
CloseDoor();
}
}
Anyway. The doors open when the game starts, they close when I am over the trigger volume, and no matter how many things I tinker with the behavior has not changed.