So I’ve got a first person camera that rotates based on mouse movement, and I am assigning the camera’s transform using a quaternion. However, when I create the rotation needed, the camera slowly tilts on the z axis, even though I have clearly set the z rotation to 0. I don’t really know how to use Quaternions, and previous answers about this problem have been very specific to the question, and when I try to fix it, I get the exact same problem, no matter how many different ways I write the code differently.
“Rotating by the product lhs * rhs is the same as applying the two rotations in sequence, lhs first and then rhs.”
So let’s try rotating the camera by applying a rotation (90, 90, 0) then (-90, 0, 0). Rotate the camera 90 degrees on the x axis then 90 degrees on the y axis and back 90 degress on the x axis. At this point you have a rotation which is a 90 degree turn on the z axis.
To keep the z rotation 0 you probably want to only apply one rotation on the x and one rotation on the y axis. For instance