【发布时间】:2017-03-06 22:06:43
【问题描述】:
我的玩家漂浮在太空中,当它应该左转或右转时,它会沿 z 轴旋转
float x = CrossPlatformInputManager.GetAxis ("Horizontal");
float y = CrossPlatformInputManager.GetAxis ("Vertical");
transform.Translate (Vector3.forward * speed * Time.deltaTime);
rigidBody.AddForce (transform.up * flySpeed * Time.deltaTime);
transform.Rotate (new Vector3 (Time.deltaTime * -y * rotateSpeed,
Time.deltaTime* x * rotateSpeed, -Time.deltaTime * -x * rotateSpeed));
【问题讨论】:
-
这既不是 C 也不是 UnityScript - 它是 C#
-
另外,查看此问题的正确工具是调试器(或使用
print调试) - 但是您总是围绕 3 个轴旋转,因此不清楚为什么您会期望不同的结果 -
我写到 C#,但是...,好吧,我从我的脚本中剪切了 z 位置,但是旋转有限
-
docs.unity3d.com/ScriptReference/Transform.Rotate.html 您同时围绕所有三个轴旋转。如果你只想绕一个轴旋转,三个欧拉角中的两个需要为零
-
我认为您在问两个不同的问题,在标题中您是在问谁来限制旋转,例如 +120 到 -120 度。但是在下一句中,您的问题似乎是游戏对象正在沿您未预料到的轴旋转。