平稳的球运动(团结)

时间:2020-02-20 21:31:24

标签: c# unity3d

我正在开发一个带球的简单3D游戏。而且球的移动不平稳。

while (i < Input.touchCount)
        {
            if(Input.GetTouch(i).position.y < ScreenHeight / 2)
            {
                if (Input.GetTouch(i).position.x > ScreenWidth / 2)
                {
                    //move right
                    rigidBody.velocity += new Vector3(0.75f, 0, 0);

                }
                if (Input.GetTouch(i).position.x < ScreenWidth / 2)
                {
                    //move left
                    rigidBody.velocity -= new Vector3(0.75f, 0, 0);

                }
            }
            ++i;
        }

如您所见,我使用刚体的速度,该速度开始缓慢,然后快速发展。但是我希望球在触摸屏幕后立即以恒定速度运动。 另外,它还在抽动,而不是平稳地移动。 你能帮我改善它吗?

1 个答案:

答案 0 :(得分:0)

请记住,物理计算必须使用FixedUpdate()事件方法:

来自MonoBehaviour.FixedUpdate()

与帧速率无关的MonoBehaviour.FixedUpdate消息,用于物理计算。

MonoBehaviour.FixedUpdate具有物理系统的频率;它被称为每个固定帧率帧。在FixedUpdate之后计算物理系统的计算。两次呼叫之间的默认时间为0.02秒(每秒50次呼叫)。使用Time.fixedDeltaTime访问此值。

参考:

希望这会有所帮助。