Every time player change his rotation, it back to 0. I suspect, that I just don’t understand entire quaternions, because english is not my native language, and I don’t understand the descriptions of methods. What is wrong with this code? Maybe should I use another method?
Jaja yeah my problem exactly.
I think this should work.
//For more direct understunding when using input with rotations.
//Since x=>y and y=>x, plus sensitivity implementation
input.x = Input.GetAxis("Mouse Y")*sensitivityX;
input.y = Input.GetAxis("Mouse X")*sensitivityY;
targetRotationX += input.x;
targetRotationY += input.y;
Quaternion xRot = Quaternion.Euler(Vector3.right *targetRotationX );
Quaternion yRot = Quaternion.Euler(Vector3.right *targetRotationY );
transform.rotation = yRot * (xRot * Quaternion.Identity);
//edit: rather try this line instead
transform.rotation = xRot* (yRot * Quaternion.Identity);
//First rotate on Y and then look up/down, that's the idea, else I think it will end up looking the wrong way.
The idea is to store the rotations as floats and then turn them into a quaternion, I don’t understand the math but I think its something like this.
If this question isn’t answer yet with the response, can you describe which rotations you’re looking for and whether this is 2d or 3d and if there are any rotation limits, etc…
Sure, starting from the end what you want to do is start with the default rotation 0º,0º,0º (Quaternion.Identity) and rotate it.
For what I have gathered, multiplying a quaternion by another quaternion rotates it that amount, but the target quaternion has to be in the right side of the multiplication and the rotation on the left side. So you first rotate it in Y (yRot*Identity) and you get the rotation 0,rotY,0. And then you rotate it in X xRot * (result).
The idea of storing the rotations as floats is to keep it simple, and since the euler to quaternion of a rotation in just one angle is (at least i think) a solid conversion with no danger, you should work with them separately and it should give you the bests results. Usually transforming an euler like (0,50,190) or (60,5,250) is not going to have an expected transformation into a quaternion, since one quaternion have multiple euler interpretations.