Hey everyone!
So I’ve been having this problem where my character’s rotation goes from -180 to 180 (the long way around - clockwise) Instead of taking the short path (counter clockwise) and it looks really weird because I’m trying to use lerp on the rotation so that the character won’t instantly rotate. And it works for every angle except when going from -180 to 180
This is the code I’m using to rotate my character:
FHitResult TraceHitResult;
PC->GetHitResultUnderCursor(ECC_Visibility, true, TraceHitResult);
FVector CursorFV = TraceHitResult.ImpactNormal;
FRotator CursorRotation = CursorFV.Rotation();
FRotator ActorRotation = GetActorRotation();
ActorRotation.Yaw = FMath::Lerp<float>(ActorRotation.Yaw, CursorRotation.Yaw, 0.1f);
SetActorRotation(ActorRotation);
It’s also worth noting that this doesn’t happen if I don’t lerp the yaw value, something like this:
FHitResult TraceHitResult;
PC->GetHitResultUnderCursor(ECC_Visibility, true, TraceHitResult);
FVector CursorFV = TraceHitResult.ImpactNormal;
FRotator CursorRotation = CursorFV.Rotation();
FRotator ActorRotation = GetActorRotation();
ActorRotation.Yaw = CursorRotation.Yaw;
SetActorRotation(ActorRotation);
This way, the rotation snap is much more noticeable (as seen here)](https://youtu.be/YSEzJcMT1UY) but it wont go the long way around.
I’d appreciate any help, tips or suggestions on how to improve my character’s rotation, especifically on how to avoid my character from going from -180 to 180 clockwise, since it looks so silly.