制作一个球跳一个固定的距离

问题描述 投票:1回答:1
void Update ()
{
    Vector3 input = new Vector3 (0, 0, 1);
    Vector3 direction = input.normalized;
    Vector3 velocity = direction * speed;
    Vector3 moveAmount = velocity * Time.deltaTime;
    transform.position += moveAmount;

    if(Input.GetKeyDown(KeyCode.Space) && isGrounded)
    {
        player.AddForce (Vector3.up * jumpForce, ForceMode.Impulse);
    }
}

由于qazxsw poi各种qazxsw poi也因每次跳跃而有所不同,因此跳跃的距离略有不同。

球将在由固定间隙分开的块之间跳跃,因此上述行为导致问题。

有什么方法可以解决这个问题并进行固定长度的跳跃吗?

c# unity3d game-physics
1个回答
2
投票

你可以使用CharacterController。确保你的游戏对象附有一个CharacterController和Collider。此外,如果您的游戏对象附有一个rigibody,可能会导致它出现意外行为,因此您可能不得不禁止它。

Time.deltaTime

查看本教程以获取参考:moveAmount

© www.soinside.com 2019 - 2024. All rights reserved.