[英]When rotating an object in Unity, the script doesn't rotate the object on the Z-axis, only the X and Y?
[英]Rotate an Object on X and Z GLOBAL axis
我有以下情况:
我的场景中有一个圆柱,并且有两个Dropdowns。 通过下拉菜单,我可以选择X轴和Z轴的旋转角度为0或90度。 此旋转始终必须在全局轴上,以便用户了解正在发生的事情。
当我在X轴上将对象旋转90度时,一切正常。 当我尝试将其在Z轴上附加旋转90度时,对象正在绕Y轴而不是Z轴旋转。
我试图直接设置transform.rotation,transform.Rotate和transform.RotateAround,但是没有任何效果。
我要做的第一件事就是始终将旋转度重置为0。
Object.transform.rotation = Quaternion.identity;
我对Eulers的尝试:
Object.transform.rotation = Quaternion.Euler(new Vector3(xRot, 0, zRot));
我的四元数尝试:
Object.transform.rotation = Quaternion.AngleAxis(xRot * 90, Vector3.right) * Quaternion.AngleAxis(zRot * 90, Vector3.forward);
我的旋转尝试:
Object.transform.Rotate(new Vector3(xRot, 0, zRot), Space.World);
我的预期结果是,无论当前旋转的对象是什么,该对象始终绕GLOBAL X / Z轴旋转。 但是我的尝试都没有导致预期的行为。
您可以使用此:
gameObject.transform.localEulerAngles = new Vector3(xRot, 0, zRot);
或对于全局轴:
gameObject.transform.eulerAngles = new Vector3(xRot, 0, zRot);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.