I figured I’d create a few test cases to make sure that the code worked even in some non-standard circumstances and discovered something weird.
Here’s the code I added to the header file:
private:
FRotator OriginalRotation{0.f, 0.f, 0.f}; // We're just initializing these at 0.f for good practices.
float OpeningYaw = 90.f;
float TargetYaw = 0.f;
Here’s my cpp file:
// Called when the game starts
void UOpenDoor::BeginPlay()
{
Super::BeginPlay();
// Each door should know how far it can open, and what state it had when closed
// By adding this here, we can avoid some revolving door bugs with every door
OriginalRotation = GetOwner()->GetActorRotation();
TargetYaw = OriginalRotation.Yaw + OpeningYaw;
}
// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// UE_LOG(LogTemp, Warning, TEXT("%s"), *GetOwner()->GetActorRotation().ToString());
// UE_LOG(LogTemp, Warning, TEXT("Yaw is: %f"), GetOwner()->GetActorRotation().Yaw);
// We're keeping FRotator OpenDoor for convenience.
FRotator OpenDoor{
OriginalRotation.Pitch,
FMath::Lerp(GetOwner()->GetActorRotation().Yaw, TargetYaw, 0.1),
OriginalRotation.Roll
};
GetOwner()->SetActorRotation(OpenDoor);
}
It’s hard do illustrated this, but here’s a screenshot. So it has motion lines I guess.
Door GOES WHEEEE!!
Please help me make it stop.