- Home /
Transform.rotation.y rotating around x and z...
I need the object to rotate around the Y axis ONLY with a value of 90 Degrees. BUT unity is also rotating the x and z around 90 degrees but I only told it to rotate around the Y axis!
here is my code, it is seperated into 2 parts, both of them give me the same results but inversed.
pragma strict
var RotateLeft : boolean;
function OnMouseDown () {
if(RotateLeft == true){
transform.parent.gameObject.transform.Rotate(0, -90, 0, Space.Self);
transform.parent.gameObject.transform.rotation.x = 270;
transform.parent.gameObject.transform.rotation.z = 0;
}
if(RotateLeft == false){
transform.parent.transform.rotation = Quaternion.AngleAxis(90, Vector3.up);
}
}
I tryed using transform.rotation.y += 90; but x & z still get messed up...
Answer by Eric5h5 · Jul 17, 2013 at 03:11 PM
Transform.rotation is a 4D quaternion, and the individual axes do not directly correspond to euler angles, nor do they use degrees. In other words, you can't use rotation.x = 270. rotation.x is not the x axis, and valid values are -1.0 to 1.0. Don't try to modify quaternions unless you completely understand them. You can use eulerAngles instead, but note what the docs say about not setting the individual axes separately.