I followed a Youtube Tutorial on how to make Coyote jump and also a jumpBuffer using the same method.
But the problem is that the player can now jump in air, and I really do not understand how this is even possible. So i don’t know how to fix this.
I thought of implementing a InputBuffer using Queue, but I think that is just overkill for only one input. So would rather find some kind of solution instead of trying something completely different.
[Header("Player Accesiblility")]
public float hangTime = 1.5f;
private float hangCounter;
public float jumpBufferLength = 0.1f;
private float jumpBufferCount;
void Update()
{
if (coll.onGround) //Coyote Time for Jump
{
hangCounter = hangTime;
}
else
{
hangCounter -= Time.deltaTime;
}
//Jump Buffer
if (Input.GetButtonDown("Jump"))
{
jumpBufferCount = jumpBufferLength;
}
else
{
jumpBufferCount -= Time.deltaTime;
}
if (jumpBufferCount >= 0 && hangCounter > 0f) //Jump Function
{
anim.SetTrigger("jump");
Debug.Log("Jump");
dustParticle.Play();
Jump(Vector2.up, false);
jumpBufferCount = 0;
if (coll.onWall && !coll.onGround)
{
WallJump();
}
}
coll.onGround is from another script, where I just used OverLapCircle.
onGround = Physics2D.OverlapCircle((Vector2)transform.position + bottomOffset, collisionRadius, groundLayer);