需要帮助修复这个跳跃缓冲区问题:玩家偶尔会双跳

问题描述

我尝试制作一个简单的跳转缓冲区和 Coyote 计时器。 如您所见,有时玩家会进行双跳,但前提是点击跳跃按钮的速度非常快。

如您所见,here> 只发生了几次。

[Header("Player Accesiblility")]
 public float hangTime = 1.5f;
 [Serializefield]
 private float hangCounter;
 [Serializefield]
 private float jumpTimer;
 public float jumpDelay = 0.25f;

private void FixedUpdate()
 {
     if (jumpTimer > Time.time && coll.onGround)
     {
         Jump(Vector2.up,false);
     }
 }
Void update(){

 if (coll.onGround) //Coyote Time for Jump
     {
         hangCounter = hangTime;
     }

     if (Input.GetButtonDown("Jump")) //Jump Function
      {
         anim.SetTrigger("jump");

         jumpTimer = Time.time + jumpDelay;
         if (!coll.onGround && hangCounter > 0)
         {
             Jump(Vector2.up,false);
             hangCounter = 0;
         }


         if (coll.onWall && !coll.onGround)
          {

             WallJump();
          }
      }
}
 private void Jump(Vector2 dir,bool wall)
  {
     rb.veLocity = new Vector2(rb.veLocity.x,0);
      rb.veLocity += dir * jumpForce;
     jumpTimer = 0f;
     hangCounter = 0;
  }

我们将不胜感激,感谢您抽出宝贵时间。

解决方法

@Mateusz 的回答对我有帮助。 他的评论: 这很可能是因为您在 Update 中而不是在 FixedUpdate 中进行物理。阅读本文以了解更多信息 (https://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html)