Lerp problem

I having problem with my code , ihoping someone can help me find the problem…
I set up two doors please see the picture


I added a parameter IsInverted to door open so i can say to the door to open to the other side.
how ever for some reason the inverted door is spinning forever… i tried various setups but nothing works…
I did notice that in the lerp function if destination is smaller than the beginning , the door spins.
it seems strange…
i added the code here hope some one can point me to the right direction…

void UdoorOpen::BeginPlay()

{

Super::BeginPlay();

InitialRotation = GetOwner()->GetActorRotation();

TargetYaw = !InvertRotattion?TargetYaw + InitialRotation.Yaw: InitialRotation.Yaw - TargetYaw;

}

void UdoorOpen::OpenDoor()

{

FRotator doorRotation = GetOwner()->GetActorRotation();

doorRotation.Yaw = FMath::Lerp(doorRotation.Yaw,TargetYaw,0.05);

GetOwner()->SetActorRotation(doorRotation);

}

Code seems fine to me, even tested it by replacing Mike’s code with it. Try recompiling?

I tried…
For some reason the left (inverted) door is spinning on the yaw axis, it does not make any sense…


The right door (the uninverted ) is working fine…

I dont know if its important but the left door is a copy of the right door and i just changed it yaw by 180 degrees through the editor…

Ahh that makes sense. GetActorRotation() returns a value between -180 and 180 and you’re trying to set its rotation to -270 which it never will.

doorRotation.Yaw is -163.812500
doorRotation.Yaw is -169.121826
doorRotation.Yaw is -174.165741
doorRotation.Yaw is -178.957428
doorRotation.Yaw is 176.490433
doorRotation.Yaw is 154.165924
doorRotation.Yaw is 132.957626
doorRotation.Yaw is 112.809700

Mike’s code works as it’s not working off of GetActorRotation but the CurrentYaw value it’s storing.

What a find!!!
But mikes solution will not help me, because the doors will rotate to different directions.


But now that i know the problem i figure it out… Thanks!!!

Not sure what lecture you’re on but with this code

and your addition of bInvertRotation it works as expected.

Edit: huh, wasn’t expecting a nice embeded view.

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