首页 > 解决方案 > 需要帮助修复这个跳跃缓冲区(问题:玩家偶尔会双跳)

问题描述

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

正如您在 <这里> 看到的那样,它只发生了几次。

[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;
  }

任何帮助将不胜感激,并感谢您的时间。

标签: c#unity3drigid-bodies

解决方案


我从@Mateusz 那里得到了帮助我的答案。他的评论:这很可能是因为你在 Update 而不是在 FixedUpdate 中做物理。阅读本文以了解更多信息(https://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html


推荐阅读