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

Need help fixing this jump buffer (Problem: Player occasionally double jumps)

我试着做了一个简单的跳转缓冲区和 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)