My door does the opposite, what i want

If I strat the game, the door opens, and if i stand on the trigger volume, it closes.
What’s the problem?

#include “OpenDoor.h”
#include “GameFramework/Actor.h”
#include “Engine/World.h”
#include “GameFramework/PlayerController.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();

}

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));
}

// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
//Poll the Trigger Volume
//if the ActorThatOpens is in the volume
if (PressurePlate && PressurePlate->IsOverlappingActor(ActorThatOpens))
{
OpenDoor();
LastDoorOpenTime = GetWorld()->GetTimeSeconds();
}
//check if it’s time to close the door
if (GetWorld()->GetTimeSeconds() - LastDoorOpenTime > DoorCloseDelay)
{
CloseDoor();
}
}

.h file:

#pragma once

#include “CoreMinimal.h”
#include “Components/ActorComponent.h”
#include “Engine/TriggerVolume.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(EditAnywhere)
float OpenAngle = -90.0f;

UPROPERTY(EditAnywhere)
ATriggerVolume* PressurePlate;

UPROPERTY(EditAnywhere)
float DoorCloseDelay = 1.f;

float LastDoorOpenTime;

AActor* ActorThatOpens; // remember pawn inherits from actor
AActor* Owner; // the owning door

};

Rotation is absolute so if you have your door rotated by +/-90 in the scene then rotating it to 0 is going to open it.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms