【问题标题】:How can I pivot on the Y axis when rotating a game object?旋转游戏对象时如何绕 Y 轴旋转?
【发布时间】:2014-11-21 10:43:16
【问题描述】:

我正在尝试在游戏对象的枢轴上旋转设定的角度。这个枢轴是倾斜的并且有点歪斜。当我使用以下代码设置角度时,它会根据世界 Y 轴旋转,如何使倾斜的游戏对象枢轴旋转?

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

【问题讨论】:

    标签: unity3d rotation


    【解决方案1】:

    要围绕枢轴旋转对象,请使用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);
    

    【讨论】:

      【解决方案2】:

      new Vector3(0,1,0) 是“世界空间”向上(与 Vector3.up 顺便说一句)。到达“本地空间”的最简单方法是使用transform.up

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

      【讨论】:

        猜你喜欢
        • 2018-08-02
        • 1970-01-01
        • 2018-06-14
        • 2016-12-11
        • 1970-01-01
        • 1970-01-01
        • 2013-05-17
        • 2021-07-12
        • 1970-01-01
        相关资源
        最近更新 更多