27. Go ahead and test your project. Try to double jump more than once. Notice that once we land from our first double jump that you can no longer do the double jump... This is because we need to do one more thing. Once the player lands, we need to set the variable (jumpPhase) back to 0. That way the next time we jump, it will work again. Action: Add a new event to our event sheet. This time add an event for Player is On Floor, and then set the variable jumpPhase back to 0. You should be familiar enough now to do this on your own, but if you need a hint your event sheet should now look like this:
28. Now go ahead and test your project again. Now the double jump is working the way I want it to. You now have a functional double jump. You can tweak any of the settings to make it work in a way that more closely matches the needs of your game. If you want to tweak it further, I will add another option to our double jump in the next few steps.
29. One thing you may have noticed about the double jump is that it is still enabled even if the player walks off a ledge. This means that they can walk off a cliff or other platform in your game and do a double jump from mid air even though they did not initially jump. While this may be fine for some games, it may also lead to unintended shortcuts and exploits depending on your level design. So now let's look at how to disable double jumping for player who have just walked off a ledge.
30. For this we are going to change our logic to test if jumpPhase is equal to 1 instead of less than 1. We will also make it so that when a player does their initial jump, we set jumpPhase to 1. This means that when they jump we set it to 1, and it then checks for that 1 value before it allows us to double jump. We will also update our double jump so that in the last step where it used to set jumpPhase to 1 (which we are now doing as soon as they jump), we will add 1 to jumpPhase instead. This means that when they double jump, it will add 1 to jumpPhase again making the value of the variable 2. This will keep them from triple jumping, etc... because we test for 1 first, not 2. While this may sound like a lot, it is actually pretty simple once you see it on the event sheet. It should now look like this:
Open full size image
You should now have a good idea how to implement a double jump and also how to tweak it to fit your needs. If you want a triple, quadrupal jump, etc... you can simply update the events to check if the variable is equal to a higher number instead of just 1. You set it to the number you want and that is the number of times they will be able to jump after the initial jump.
If you want more ideas on how to implement it as a powerup, or other things you can do with the type of events we have worked with today, feel free to check out my wall jumping tutorial which also covers how to make the jump events powerUp based. That way if you only want the player to be able to use the special jumping moves when they have collected a powerUp, you can do that as well. Platformer Enhancements - Wall Jumping
Thanks for taking the time to walk through this tutorial, as always if you have any suggestions or feedback, please feel free to let me know. And again, if you found this tutoiral helpful, please use the voting buttons to make it easier for others to find it as well.
Unlock your full gamedev potential
Upgrade to the Personal Edition of Construct 2, it has way more features and won't holding back from making money and using your full creativity like the free edition does. It's a one off payment and all Construct 2 editor updates are free for life!
Plus, it's got a lot of additional features that will help you save time and make more impressive games!