Do you use Quarternions? [Fixed!]

I just did this the other day for reading my phone’s device orientation to aim in space.

It’s a bit weird in UE because UE loves FRotators for everything which is basically Euler and you get the dreaded gimbal lock. I wasn’t able to properly use the PlayerController’s accumulated rotation input since that’s an FRotator.

In Unreal, forward is X, up is Z, and side is Y. Or maybe forward was Y and side was X. I need to look at my code again.

So, to roll, you create a quaternion around the forward pointing axis. The pitch, you create a quaternion around the side axis. The yaw you rotate about the up facing axis.

I created these 3 separate quaternions individually based on the 3 components and then multiplied my current actor rotation by them.

Using the traditional euler won’t work because roll won’t be relative to your current orientation, but relative to if you were looking straight ahead. Basically as if pitch was 0.

Hopefully this isn’t too confusing. I can post the code later. I think people above said basically the same thing as I did.

It may be possible to do it slightly more efficiently with one quat instead of 3 individual quats.