有速度时在 OX 和 OZ 上旋转刚体球 - Unity 3D

问题描述

我想拥有以下东西: 当我在 OX 上有速度时,我只想在 OZ 上进行负旋转。 当我在 OZ 上有速度时,我只想在 OX 上有正旋转。 就我而言,球的移动非常奇怪,效果很好。如何解决这个问题? 你能给我一个具体的例子吗?我什么都试过了。

即使有这些限制,当我不想时,球也会在 OY、OX/OZ 上旋转。

     if (Input.GetMouseButtonDown(0) && GameManager.Instance.gameOver == false)
            {
                SwitchDirection();
            }
     
    void SwitchDirection()
        {
            Vector3 rotationToX = new Vector3(Random.Range(20f,100f),0);
            Vector3 rotationToZ = new Vector3(0,Random.Range(-20f,-100f));
           
            if (rb.veLocity.z > 0)
            {
                rb.veLocity = new Vector3(GameManager.Instance.initialSpeedBall,0);
                rb.AddRelativetorque(rotationToZ,ForceMode.Impulse);
                rb.constraints = RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezeRotationX;
            }
            else if (rb.veLocity.x > 0)
            {
                rb.veLocity = new Vector3(0,GameManager.Instance.initialSpeedBall);
                rb.AddRelativetorque(rotationToX,ForceMode.Impulse);
                rb.constraints = RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezeRotationZ;
           
            }
         
        }
     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)