Turn In Place Almost Perfect

Need help fixing a small bug, when turning (say right first however many times), the turn in place works, but when i turn left the second time after turning right first the left turn is messed up (root yaw offset is being set and sign is flipping incorrectly). vice versa if i turn left first then right the second time, left works great and right turn is messed up.

I feel like this is a job for quaternions. You won’t have the sign issue with them.

The sign flip is more random than i thought after testing and debugging. Could you type some example of a UE quaternion FQuat, I’m not sure how to start?

This might work. Haven’t tested it though:

#include "Math/Quat.h"

void AYourCharacter::RotateInPlaceWithQuaternion(float DeltaTime)
{    
    if (FMath::IsNearlyZero(GetCharacterMovement()->Velocity.SizeSquared()))
    {        
        FQuat CurrentRotation = GetActorQuat();

        // Create a quaternion for the desired rotation (ie. rotating around the Z-axis)
        FQuat DesiredRotation = FQuat(FRotator(0.0f, RotationSpeed * DeltaTime, 0.0f));
       
        FQuat NewRotation = DesiredRotation * CurrentRotation;        
        SetActorRotation(NewRotation);
    }
}

Thanks, I’ll see what i can come up with.

So I’m using rotate root bone to keep my feet forward until yaw offset is 90 ,then using yawoffsetABS to keep from passing 180 -180 which eliminates sign flip. I tried FRotators, no change. Now trying quaternions, just not sure how to properly normalize or get a Yaw from it, or delta.