2014-11-21 127 views
1

我試圖在遊戲對象的樞軸上旋轉設定的角度。這個樞軸是傾斜的,有點歪斜。當我用下面的代碼設置角度時,它根據世界Y軸旋轉,我如何在傾斜的遊戲對象的軸心上進行旋轉?對象樞軸Y軸上的旋轉[UNITY]

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

在此先感謝

回答

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