- Home /
The question is answered, right answer was accepted
Quaternion.euler gives me glitch. Why?
Hello!
I'm trying to make a FPS controller movement and i spend like all day to fix this problem but can't find an answer, so if anyone can help me with some links or ideas for fixing, i will be grateful
This is my code with the problem:
mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation = -mouseY;
var euler = new Vector3(xRotation, 0, 0);
transform.rotation = Quaternion.Euler(euler.x, euler.y, euler.z);
Answer by myzzie · Nov 17, 2020 at 11:02 PM
first of, mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
returns a small value. secondly, var euler = new Vector3(xRotation, 0, 0);
creates a quaternion with x being this small value, then you set your rotation to that.
do mouseY +=
instead. and don't forget to clamp it
It's perfect now, the mistake of attention because I didn't see that I didn't add them but I was sure I was doing it.... Thank you so much for the answer
It's better to use - instead of + mouseY -=
because the rotation is reversed(up is down and down is up)