Quaternion Roation Mouse Script
Can anyone help me fix my script for moving my Mouse, im quite new to Unity and my first MouseScript was made with Euler Angles but shortly i noticed the Gimbal Lock is a real big problem so i tried making my mouse script with Quaternion rotations.
`void MouseControl()
{
Quaternion movementX;
Quaternion movementY;
Quaternion movementCombined;
float xmov = 0.0f;
float ymov = 0.0f;
xmov += Input.GetAxis("Mouse X");
ymov += Input.GetAxis("Mouse Y");
movementX = Quaternion.AngleAxis(xmov, Vector3.up);
movementY = Quaternion.AngleAxis(ymov, Vector3.right);
movementCombined = movementX * movementY;
cameraT.rotation *= Quaternion.Lerp(cameraT.rotation, movementCombined , Time.time);
}
So my problem is that the rotation of the camera happens based on the direction the player looks in, this means if the player looks 90 degrees down he can change the Z axis instead of the Y axis. This is a big problem for me because even in normal use the view tilts when turning. Im hoping someone can suggest a fix for my code snippet. I have started playing around with Unity 3 days ago and i am looking forward to learn programming more and understand more of Unity everyday. Im happy if you can help.
Thank you.
`
It's difficult to tell what you are trying to achieve, so this may be completely wrong, but perhaps changing lines 10 and 11 to the following will fix the issue:
movementX = Quaternion.AngleAxis(xmov, Vector3.up);
movementY = Quaternion.AngleAxis(ymov, transform.right);
Your answer
Follow this Question
Related Questions
How to rotate Object with Mouse drag (specifications below) 2 Answers
Set the rotation axis of the camera 0 Answers
Rotate object in 3d space along one axis in the direction of movement vector. 0 Answers
Help limiting Camera rotation, spinning out of control. 1 Answer
Xbox one controller spinning 0 Answers