Download

Combined quaternion rotation issue

Hi, there is something I am obviously missing regarding quaternion rotation, and the below example running on character tick demonstrates it. I am expecting this code to pitch the character by 20 degrees upwards then rotate the character around the new character up vector. But this is not what is happening, while rotating, the character up vector is constantly changing direction. Thanks to let me know what I am missing!



on character tick:

FTransform actorTransform = GetActorTransform();
FQuat targetRotation = actorTransform.GetRotation();

static bool doOnce = true;
if (doOnce)
{    
    // pitch up by 20 deg.
    targetRotation *= FQuat(targetRotation.GetRightVector(), FMath::DegreesToRadians(-20.f));
    doOnce = false;
}

// yaw rotation around the up vector
targetRotation *= FQuat(targetRotation.GetUpVector(), FMath::DegreesToRadians(10.f * DeltaTime));

actorTransform.SetRotation(targetRotation);
SetActorTransform(actorTransform);


Solution found, need to use FVector::RightVector and FVector::UpVector instead of targetRotation.GetRightVector() and targetRotation.GetUpVector()



FTransform actorTransform = GetActorTransform();
FQuat targetRotation = actorTransform.GetRotation();

static bool doOnce = true;
if (doOnce)
{    
    // pitch up by 20 deg.
    targetRotation *= FQuat(FVector::RightVector, FMath::DegreesToRadians(-20.f));
    // targetRotation *=  FQuat::MakeFromEuler(FVector::RightVector * 20.f); // alternative, works the same
    doOnce = false;
}

// yaw rotation around the up vector
targetRotation *= FQuat(FVector::UpVector,  FMath::DegreesToRadians(10.f * DeltaTime));
//targetRotation *= FQuat::MakeFromEuler(FVector::UpVector * (10.f * DeltaTime)); // alternative, works the same

actorTransform.SetRotation(targetRotation);
SetActorTransform(actorTransform);