船在转弯时试图倾斜时会在 z 轴上移动位置?

ship moves position on z axis when trying to tilt it while turning?

我正在统一制作一个 2.5D 游戏,它是关于一艘 space 飞船穿越 space 的,更像传统的 space 飞船游戏。

我希望我的space飞船在玩家像飞机一样转弯时倾斜一点,就像这架飞机在转弯一样:

这是我的屏幕船转弯时的样子:

我想让它倾斜一点,这是我现在的时刻代码

    void Turn()
    {
        float RotationCount = Input.GetAxis("Horizontal");
        float TurnShip = turnSpeed * Time.deltaTime * Input.GetAxis("Horizontal");
        if (Input.GetAxis("Horizontal") < 0)
            ForwardTransform.Rotate(0, TurnShip,10*Time.deltatime)
        else if (Input.GetAxis("Horizontal") > 0)
            ForwardTransform.Rotate(0, TurnShip,-10*Time.deltatime);


        //if (RotationCount < 0)
        //    myT.Rotate(0, TurnShip, 9);
        //else if (RotationCount > 0)
        //    myT.Rotate(0, TurnShip, -9);
    }

这是旋转脚本,下面是推特股票

    void Thrust()
    {

        if (Input.GetAxis("Vertical") > 0.75f)
        {
            V = Input.GetAxis("Vertical");
        }


        myT.position += myT.forward * movementSpeed * Time.deltaTime * V;
    }

但是当我使用此代码时,船会根据运动改变其在 Z 轴上的位置,因为船头会向下或向上转动

如何在不改变 Z 轴位置的情况下倾斜飞船

发货初始位置:

用户转船时:

我还应该用什么其他方式转动我的船?

为什么不拥有一个中间对象并使宇宙飞船成为它的子对象?

因此,您可以旋转这个中间对象,而不是旋转船,然后您可以移动船底。这里的技巧是中间对象只在一个轴上旋转,而船只在一个轴上旋转(相对于它的父变换)。

这将避免任何 Euler angle/Quaternion/moving 参考框架业务,对于这样一个简单的问题,您应该需要它。