【发布时间】:2016-04-19 16:56:15
【问题描述】:
我正在尝试使用用户控件旋转球体。
void RotateGlobe() {
SetLock();
if (Input.GetMouseButton(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
userInput.x = Input.GetAxis("Mouse X");
userInput.y = Input.GetAxis("Mouse Y");
if (userInput.magnitude > 0 & Physics.Raycast(ray, Mathf.Infinity, LayerMask.NameToLayer("UI")))
{
Vector2 movement = new Vector2(Mathf.Sign(userInput.x), Mathf.Sign(userInput.y));
globe.transform.rotation =
Quaternion.Slerp(globe.transform.rotation,
Quaternion.Euler(0, movement.y * 90, movement.x * 180 + globe.transform.rotation.eulerAngles.x),
Time.time * speed);
}
}
RemoveLock();
}
我不太了解四元数(再说一次,谁真正了解),但地球不仅没有正确响应用户输入,而且卡在 x 轴上。我知道它可能是通过不移动而从 180 到 -180 的最短路径。
我想在这一点上,我完全愿意更改此代码以支持更好的方法(不是 slerp),但我完全卡住了,以前的方法同样困难和不稳定。
你建议我如何旋转这个球体?
作为奖励,如果我可以约束一个轴,我们会很棒。我真的不想旋转超过 90 或 -90。
【问题讨论】:
-
永远不要以任何理由使用四元数,Anders。您可以使用 localEulerAngles 或 eulerAngles 设置所有角度,或者更好地只需使用 Rotate 或 RotateAround
-
我很欣赏这背后的情绪,因为我也讨厌它们,但是 Slerp 和 Lerp 是如此的流畅和优化......另外 RotateAround 在 5.4 中已被弃用。
-
RotateAround 没有被弃用,你只是在使用古老的:google answers.unity3d.com/answers/540399/view.html
-
好吧。我想这就是我明天要做的事情......谢谢。这绝对是我不明白的事情......你为什么要弃用这么有用的东西哈哈?如果你想写 RotateAround 会起作用,ID 很乐意选择它作为答案。
标签: unity3d user-controls rotation quaternions gameobject