Hello! I'm currently having an issue with implementing double jump in my game. I'm using the code from this video as a base(because i really like how the jump works:https://youtu.be/vFsJIrm2btU), the current code below is my best attempt at making it, it's buggy and it barely works, I have tried other ways than this one, but they either broke the normal jump or just didn't work at all. Here's the code:
float jumpRemember = 2;
void FixedUpdate(){
Vector2 v2GroundedBoxCheckPosition = (Vector2)transform.position + new Vector2(0, -0.01f);
Vector2 v2GroundedBoxCheckScale = (Vector2)transform.localScale + new Vector2(-0.02f, 0);
bool bGrounded = Physics2D.OverlapBox(v2GroundedBoxCheckPosition, v2GroundedBoxCheckScale, 0, lmWalls);
fGroundedRemember -= Time.deltaTime;
if (bGrounded)
{
fGroundedRemember = fGroundedRememberTime;
jumpCount = jumpRemember;
}
fJumpPressedRemember -= Time.deltaTime;
if (Input.GetButtonDown("Jump") && jumpCount != 0)
{
fJumpPressedRemember = fJumpPressedRememberTime;
}
if (Input.GetButtonUp("Jump") && jumpCount != 0)
{
if (rigid.velocity.y > 0)
{
rigid.velocity = new Vector2(rigid.velocity.x, rigid.velocity.y * fCutJumpHeight);
}
}
if ((fJumpPressedRemember > 0) && (fGroundedRemember > 0) || Input.GetButtonDown("Jump") && jumpCount != 0)
{
fJumpPressedRemember = 0;
fGroundedRemember = 0;
rigid.velocity = new Vector2(rigid.velocity.x, fJumpVelocity);
jumpCount--;
}
if(jumpCount <= 0)
{
Debug.Log($"Set to zero, soz,{jumpCount}");
}```