- Home /
Question by
unity_c1zol9zYXCBE5Q · Apr 16, 2018 at 07:51 PM ·
rotationquaternionmouselookquaternions
How do i make my Mouselook behave when changing the z rotation?
My Quaternions-based mouselook works perfectly fine when my character is upright but when the z rotation of my character is changed everything behaves weird. Here is my code:
void Update () {
if (axes == RotationAxes.MouseXAndY)
{
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationX = Mathf.Clamp(rotationX, minimumX, maximumX);
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);
Quaternion yQuaternion = Quaternion.AngleAxis(rotationY, -Vector3.right);
transform.rotation = xQuaternion * yQuaternion;
}
else if (axes == RotationAxes.MouseX)
{
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationX = Mathf.Clamp(rotationX, minimumX, maximumX);
Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);
transform.rotation = xQuaternion;
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
Quaternion yQuaternion = Quaternion.AngleAxis(-rotationY, Vector3.right);
transform.rotation = yQuaternion;
}
Thanks in advance. (yes i am a noob)
Comment