Unity-围绕2D点旋转对象

时间:2018-06-27 17:51:51

标签: unity3d rotation 2d

我一直在Unity中进行2D游戏,因此我需要找到一种方法来围绕特定点旋转精灵。我知道对于3D游戏,Unity具有内置的transform.RotateAround()函数,但是我不确定如何实现2D等效。如果有人可以提供帮助,我们将非常感谢您的答复。

3 个答案:

答案 0 :(得分:3)

您可以使用相同的功能。 transform.RotateAround()的度数为Vector3 pointVector3 axisfloat angle

点和角度是很容易说明的,但轴的角度要少一些。这实质上是旋转方向。在默认的Unity2D游戏中,z是您的深度(进入屏幕),您需要绕Z轴旋转:new Vector3(0,0,1)Vector3.forward

尝试类似:

Vector3 point = new Vector3(5,0,0);
Vector3 axis = new Vector3(0,0,1);
transform.RotateAround(point, axis, Time.deltaTime * 10);

答案 1 :(得分:0)

如果您想尽办法解决这些转换功能,则可以采用另一种方法。只需在要旋转的点上创建一个新的游戏对象。然后将精灵作为该游戏对象的子代。旋转游戏对象时,子画面应在该点附近移动。

答案 2 :(得分:0)

实际上,您可以使用一些GameObject作为锚点:

    public GameObject anchor;
    public float velocidad;
    void Start () {
        velocidad = 50f;
    }

    // Update is called once per frame
    void FixedUpdate () {

        transform.RotateAround(anchor.transform.localPosition, Vector3.back, Time.deltaTime*velocidad);
    }
相关问题