【发布时间】:2014-11-21 10:43:16
【问题描述】:
我正在尝试在游戏对象的枢轴上旋转设定的角度。这个枢轴是倾斜的并且有点歪斜。当我使用以下代码设置角度时,它会根据世界 Y 轴旋转,如何使倾斜的游戏对象枢轴旋转?
steer.transform.rotation = Quaternion.AngleAxis(angle, new Vector3(0 ,1, 0));
【问题讨论】:
我正在尝试在游戏对象的枢轴上旋转设定的角度。这个枢轴是倾斜的并且有点歪斜。当我使用以下代码设置角度时,它会根据世界 Y 轴旋转,如何使倾斜的游戏对象枢轴旋转?
steer.transform.rotation = Quaternion.AngleAxis(angle, new Vector3(0 ,1, 0));
【问题讨论】:
要围绕枢轴旋转对象,请使用Transform.RotateAround() 方法。所以代码看起来像:
Vector3 pivot = ...; // Object's pivot in world coordinates
float angle = ...; // You also want to multiply angle by Time.deltaTime
// To rotate around the world's up axis
steer.transform.RotateAround(pivot, Vector3.up, angle);
// To rotate around the object's up axis
steer.transform.RotateAround(pivot, steer.transform.up, angle);
【讨论】:
new Vector3(0,1,0) 是“世界空间”向上(与 Vector3.up 顺便说一句)。到达“本地空间”的最简单方法是使用transform.up
【讨论】: