I tried to make a simple Jump buffer and Coyote timer.
As you can see, sometimes the player does a double jump, but only if the jump button is clicked very fast.
As you can see <here>, it only happens a few times.
[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;
}
Any help will be much appreciated, and thank you for your time.
question from:
https://stackoverflow.com/questions/65847846/need-help-fixing-this-jump-buffer-problem-player-occasionally-double-jumps 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…