Jump Limiting in bolt

I have been trying to limit my character’s jumps.
My Idea is to have a variable, JumpAmount, that reduces by 1 when you press the jump button, and resets to 1 when you touch the ground.
The first image is the full graph, and the second and third are the unfinished snippets of code I’ve made. I need to figure out how to connect these to the full graph.


7912873--1009294--snippet 1.PNG

First, your physics should be connected to Fixed Update and not Update. Usually, the way people handle it is getting inputs in Update, setting a variable (I usually use a float to store the input value) then in Fixed Update they fire the physics stuff when the variable is not zero, maybe set another bool to true if moving, false if not moving. Jumping is a complicated thing though, First, you need to know if a character is grounded, so you should have your ground in it’s own layer, then you use something like CollisionEnter2D and CollisionExit2D to detect when it comes into contact with anything on the “Ground” layer and set a variable (a bool, something like IsGrounded) to determine whether they’re already jumping, in the air, or on the ground. You may also want a Bool like IsJumping to be able to know the difference between when a character is jumping vs falling (if it matters to the way you want your game to play).
Now, to allow for more than one jump, you have a variable that stores max number of jumps (MaxJumps) and a variable that stores the counter for jumps used (JumpCounter). Every time you detect the character is grounded, you also set that second variable back to zero. Every time (in Fixed Update) that you fire the jump physics you first check to make sure you haven’t gone over your MaxJumps, and once the jump actually starts (you’ve applied the force) you increase the JumpCounter.

1 Like

Ok, I think I understand… I’ll get back to you on if it works