Platformer Enhancements - Double Jump

7

Index

Stats

14,780 visits, 38,966 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 4 Feb, 2013. Last updated 19 Feb, 2019

20. To solve the infinite jumping issue we need to be able to detect how many times the player has hit the up arrow after their initial jump. The obvious way of doing this is with a variable. We will create a variable called jumpPhase to track if the player has already jumped, and we can also use to to tell how many times they have hit the up arrow.

21. Action: On your event sheet right click below all of your current events (in the blank area below them) and choose the option for add global variable.

22. Action: In the windows that comes up name the variable jumpPhase and leave the rest at the default. The variable will hold a number and we will start it at 0.

23. Now we need to update our double jump event to check the value of this variable and react accordingly. Here is how I plan for mine to work. When the user jumps the first time we do noting with the variable, when they try to double jump we will check to see if the variable's value is less than 1. If it is, then we allow them to double jump. Once they have double jumped, we will set the value of the variable to 1 to make sure they can't do it again. You can adjust this to fit your needs. In my case I want a double jump, not triple, quadruple, etc...

24. Action: On your event sheet add another condition to our On Up Arrow Pressed event. Right click the Up Arrow Pressed event and choose "Add Another Condition". For the new condition add the following: System>Compare Variable. Now choose jumpPhase>Less Than 1 then click done.

25. Action: Add a new action right below our set Vector Y -500 action. In this new action choose System>Set Value and set jumpPhase to 1. Click Done.

26. We need to make sure that we change the variable to 1 as the last step of our double jump, otherwise if you set it sooner, you may accidently keep it from working at all. Now our event checks if the variable is less than one (in our case it starts at 0), then does the double jump, then sets it to 1. This keeps the player from doing more than two jumps. Your event sheet should now look like this:

  • 1 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • This is amazing, Thank you! This may help me with triggering the jump sound better. Right now my player can press jump and while in the air can continue to press jump and the sound will trigger. If I can trigger it on jump phase that would alleviate my issues I believe!