Carousel door when initial yaw is greater than 90 degrees. Building Escape

Building-escape tutorial. around 102

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

	InitialYaw = GetOwner()->GetActorRotation().Yaw;
	TargetYaw = InitialYaw + 90.0f;

	
	UE_LOG(LogTemp, Warning, TEXT("This %f"), InitialYaw);
}

// Called every frame=1
void UOpenTheDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{

	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
	CurrentYaw = GetOwner()->GetActorRotation().Yaw;
	
	if (CurrentYaw < TargetYaw - 1.0f)
	{
		UE_LOG(LogTemp, Warning, TEXT("Yaw is: %f"), GetOwner()->GetActorRotation().Yaw);
		FRotator OpenDoor(0.0f, TargetYaw, 0.0f);
		OpenDoor.Yaw = FMath::FInterpTo(CurrentYaw, TargetYaw, DeltaTime, 2);
		GetOwner()->SetActorRotation(OpenDoor);


	}
}

The door comes almost to a stop, then speeds up again doing a carousel type thing. This occurs if the initial yaw was greater than 90 degrees. Seems when the yaw hits 180, it then becomes -180.

LogTemp: Warning: Yaw is: 178.742538
LogTemp: Warning: Yaw is: 179.066345
LogTemp: Warning: Yaw is: 179.368576
LogTemp: Warning: Yaw is: 179.650665
LogTemp: Warning: Yaw is: 179.913940
LogTemp: Warning: Yaw is: -179.840347
LogTemp: Warning: Yaw is: -155.610916
LogTemp: Warning: Yaw is: -132.996613
LogTemp: Warning: Yaw is: -111.889908
LogTemp: Warning: Yaw is: -92.190491
LogTemp: Warning: Yaw is: -73.804329
LogTemp: Warning: Yaw is: -56.643780
LogTemp: Warning: Yaw is: -40.627468
LogTemp: Warning: Yaw is: -25.678783

Et cetera.
If the inital yaw was less than 90 degrees, everything works as expected.
This is not the first time i have had issues with the way UE4 calculates/maps circles. Any solutions or suggestions would be appreciated.
Thank you

I changed the code to the following. It is now working as expected.

#include "OpenTheDoor.h"
#include "GameFramework/Actor.h"

// Sets default values for this component's properties
UOpenTheDoor::UOpenTheDoor()
{
	// 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 UOpenTheDoor::BeginPlay()
{
	Super::BeginPlay();

	InitialYaw = GetOwner()->GetActorRotation().Yaw;
	CurrentYaw = InitialYaw;
	TargetYaw += InitialYaw;


	UE_LOG(LogTemp, Warning, TEXT("This %f"), InitialYaw);
}

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

	if (CurrentYaw < TargetYaw)
	{
		CurrentYaw = FMath::FInterpTo(CurrentYaw, TargetYaw, DeltaTime, 3);
		//CurrentYaw = FMath::Lerp(CurrentYaw, TargetYaw, 0.02f);
		FRotator DoorRotation = GetOwner()->GetActorRotation();
		DoorRotation.Yaw = CurrentYaw;
		GetOwner()->SetActorRotation(DoorRotation);
		UE_LOG(LogTemp, Warning, TEXT("Intitial Yaw is : %s"), *GetOwner()->GetActorRotation().ToString());
		UE_LOG(LogTemp, Warning, TEXT("Yaw is : %f"), GetOwner()->GetActorRotation().Yaw);
		UE_LOG(LogTemp, Warning, TEXT("CurrentYaw is : %f"), CurrentYaw);
	}

Note that if you change the 3 to a 2 the problem will be back.

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

Privacy & Terms