Hey guys!
I’ve got a bit of a problem that I just can’t figure out how to solve.
I’m making a new character controller script and I’m planing an having a double jump in my game when it is unlocked. I’m using Rigidbody.AddForce so I can make another script working (not relevant here).
Everything works so far except that the player can jump twice even though double jump is not active. Here’s the relevant code:
if(grounded == true)
{
maxVel = 15.0f;
timesJumped = 0;
}
else
{
maxVel = 7.5f;
}
if(Input.GetKeyDown(KeyCode.W) && timesJumped < maxJumps)
{
Debug.Log("Check " + timesJumped);
timesJumped++;
rBody.AddForce(gameObject.transform.up * jump, ForceMode.Impulse);
}
The problem seems to be, that when I hit W to fast after jumping once, that it doesn’t increment “timesJumped” fast enough and because of that the game executes the code a second time… The even stranger thing about that is, that “timesJumped” increments only once even if the player jumps twice.
I’ve even tied using a Coroutine to account for this “lag”, but nothing works. The player is able to jump twice regardless.
If you need more information’s, just ask and I will provide it ^^
Thanks in advance!