Skip to content

marcelpatrick/Escape_Simple

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Escape_Simple

Here is a more simplified version. It is a scape room with a trigger volume. If the actor overlaps the trigger volume it opens a door:

1- Create the Trigger Volume and place it in your level

image

2- Select the door and create a new C++ component for it

image

3- Code

In the header file, instantiate the trigger volume variable, the variable for the actor that will open the door and the angle to which the door will open

private:

UPROPERTY(EditAnywhere)
ATriggerVolume* PressurePlate = nullptr;

UPROPERTY(EditAnywhere)
AActor* ActorThatOpens; 

UPROPERTY(EditAnywhere)
float OpenAngle = 180.f;

On begin play assign the actor pawn to the actor that opens variable

void UOpenDoor::BeginPlay()
{
	Super::BeginPlay();

	ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();

	UE_LOG(LogTemp, Warning, TEXT("open angle is %f"), OpenAngle);
}

On Tick, craete an if statement for when the trigger volume is overlapping with the actor If true, Call OpenDoor Function

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

	if (PressurePlate && PressurePlate->IsOverlappingActor(ActorThatOpens))
	{
		OpenDoor(DeltaTime);
	}
	
}

The OpenDoor Function does

  • 1- gets the actor yaw and assigns to a float
  • 2- Initializes a rotator variable
  • 3- uses and interpolator between the current yaw and the open angle and assigns this to the yaw parameter of the rotator
  • 4- sets the actor rotation to the open door variable that we just updated
void UOpenDoor::OpenDoor(float DeltaTime)
{
	UE_LOG(LogTemp, Warning, TEXT("vamos abrir a porta"));

	float CurrentYaw = GetOwner()->GetActorRotation().Yaw;
	FRotator OpenDoor(0.f, 0.f, 0.f);
	OpenDoor.Yaw = FMath::FInterpTo(CurrentYaw, OpenAngle, DeltaTime, 1);
	GetOwner()->SetActorRotation(OpenDoor);

	UE_LOG(LogTemp, Warning, TEXT("door rotation is %s"), *GetOwner()->GetActorRotation().ToString());
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published