How to combine world and local rotation

I have this kind of code:

SetWorldRotation;
AddLocalRotation;

I set the world roll rotation of the actor, then rotate it by a certain degree around is up vector (a local yaw rotation).
Is there a way to convert the local rotation in world space and use just SetWorldRotation?

Not sure if I know exactly what you mean, but like this? SetWorldRotation(FRotator(myworldpitch, myworldyaw+mylocalyaw, myworldroll));

I mean that, right after SetWorldRotation, object transform will be rotated by a certain degree around the world X Axis. At this point a rotation around world Y Axis or object (local) rotated Y Axis will produce different result (Rotation in editor Roll = 56, Yaw = -40):

(World)->(Pitch=0.000000,Yaw=-39.999977,Roll=55.999958)
(Local)->(Pitch=32.201244,Yaw=-25.136806,Roll=48.635815)

I want to use RInterpTo to permorf a smooth rotation, but I can’t do that using SetWorldRotation+AddLocalRotation. The actor is a StaticMeshActor. I tried to apply world rotation to the actor itself and local rotation to the static mesh component, but it didn’t work probably due to the fact that the static mesh component is the root component and the rotation is automatically transferred onto the actor. I thik I could create a custom “static mesh wrapper actor” with a fake root component and the static mesh component, but I don’t really like this solution

Maybe like this?:

FQuat TargetRot = YourWorldRot.Quaternion() * YourLocalRot.Quaternion();
FRotator FinalW = FMath::RInterpTo(GetActorRotation(), FRotator(TargetRot), DeltaTime);
SetWorldRotation(FinalW);
1 Like

I thought about using quaternions, but I know very little about it. I will try and see if that works. Thanks!