物体枢轴Y轴上的旋转[UNITY]

时间:2014-11-21 10:43:17

标签: unity3d rotation

我试图在游戏对象的枢轴上旋转设定角度。该枢轴倾斜并略微倾斜。当我使用以下代码设置角度时,它会根据世界Y轴旋转,如何在倾斜的游戏对象枢轴上进行旋转?

steer.transform.rotation = Quaternion.AngleAxis(angle, new Vector3(0 ,1, 0));

提前致谢

2 个答案:

答案 0 :(得分:0)

new Vector3(0,1,0)是"世界空间" up(与Vector3.up btw相同)。到达"本地空间的最简单方法"将使用transform.up

http://docs.unity3d.com/ScriptReference/Transform-up.html

答案 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);