I thought that there was a more efficient and less redundant way of making the open and close door function. I decided to put them into one function to repeat less code and make another parameter where you have to tell the function where the ending yaw should be.
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (PressurePlate && PressurePlate->IsOverlappingActor(ActorThatOpens))
{
OpenCloseDoor(DeltaTime, OpenAngle);
}
else
{
OpenCloseDoor(DeltaTime, InitialYaw);
}
}
void UOpenDoor::OpenCloseDoor(float DeltaTime, float Yaw)
{
CurrentYaw = FMath::FInterpTo(CurrentYaw, Yaw, DeltaTime, 3.5); // Smooth transition door open
FRotator DoorRotation = GetOwner()->GetActorRotation(); // create editable variable that has the current door rotation
DoorRotation.Yaw = CurrentYaw; // set the yaw to whatever the interp function has it set to currently
GetOwner()->SetActorRotation(DoorRotation); // after all the calculations above, set the door to the current rotation that the lerp is calculating
return;
}
I’m only assuming this is better than what was shown, but if it’s not or if there’s anything I need to note please let me know