Hi, thanks for taking the time and checking out my question. I’m trying to set up a simple double jump mechanic with this script
int jumps = 2;
...
void jumping()
{
Debug.Log(jumps);
grounded = Physics2D.OverlapCircle(groundCheck.position, radius, groundMask);
if (grounded)
{
jumps = 2;
}
if (Input.GetButtonDown("Jump") && jumps > 0)
{
jumps--;
rb.velocity = Vector2.up * jumpForce;
}
}
this script sometimes works fine but sometimes I’m able to jump 3 times when debugging it showed in the console that whenever I get that case where my player is jumping 3 times it doesn’t subtract when the “jumps” is on 1. it goes like this: 2 → 1 → 1 and finally 0 but it repeated 1 so I jumped 3 times…
Thanks a lot, solutions are deeply appreciated.