- Home /
Lock Z rotation to 0
I am rotating a GameObject on the X and the Y axis ONLY, but suddenly the z rotation wants to rotate as well. So i am looking to lock the Z rotation of this object. This GameObject does not have a rigidbody. Heres a piece of my code...
cameraMovementsY = new Vector3 (0, Input.GetAxis ("Mouse X") lookSpeed, 0); cameraMovementsX = new Vector3 (-Input.GetAxis ("Mouse Y") lookSpeed, 0, 0);
transform.Rotate (cameraMovementsX Time.deltaTime); transform.Rotate (cameraMovementsY Time.deltaTime);
Thanks for helping!
When you perform rotations in 'euler' angles you are subject to Gimbal lock.
If the rotation is fine at first and then the third axis is 'picked up' by another, it is gimbal lock, I do believe.
Answer by KwahuNashoba · Oct 02, 2015 at 08:31 AM
Rotation by Euler angles can be pretty much unpredictable, if you want to know how it works and what is down side of it look this video https://www.youtube.com/watch?v=zc8b2Jo7mno . Like @meat5000 said, it may be that gimbal lock occured.
Try this:
transform.rotation *= Quaternion.Euler(cameraMovementsX , cameraMovementsY, 0f) * Time.deltaTime;
That piece of code doesnt work. The z axis still rotates...
Answer by TheDawningLegend · Oct 03, 2015 at 02:38 PM
Ive fixed the problem using something else. Thanks for the help guys, i wouldn't have learned the gimbal thing without you.
$$anonymous$$ay you share the solution you ended up implementing? I'm having the same issue