2D Mobile Game: Double Jump Ability

Ryan McCoach
3 min readJun 5, 2022

--

Intro

In this article, we will cover how to add a double jump mechanic to a platformer. In my game, this ability can be gained when purchased at a shop but the logic remains the same no matter how the player gains the ability.

Check out my previous articles that cover the jump mechanic for a platformer. This will you understand the adjustments needed to make the double jump logic work.

Player Jump: https://ryanjmccoach.medium.com/2d-mobile-game-player-jump-8cb24924505c

Player Jump Optimized: https://ryanjmccoach.medium.com/2d-mobile-game-player-jump-optimized-34ac87b9e5ed

Current Jump Script

The current jump script is in the update method and is always checking to see if the player is touching the ground. If the player is touching the ground and presses the jump button, the player will jump and can only jump again once they have landed back on the ground

Double Jump

For the double jump to work, we will need to keep track of how many times we have jumped. We create a int variable, jumpCount, that account for and check the amount of times the player has jumped.

When the player pressed the jump button, we want to not only check to see if the player is touching the ground but also if the jump count is equal to 0 (this means the player hasn’t jumped yet). If this is true, we have the player jump like before, but we increment the jump count.

When the player hits the ground again, we want to reset the jump count back to 0.

For use to be able to jump while the player is not touching the ground, we want to check to make sure isGround = false.

Then, we want to make sure our jump count is equal to 1 and we have the power up to complete the double jump. If all of these conditions are met, we jump and increment the jump count.

Now, the jump count is equal to 2 and since it is equal to 2, the condition of jump count = 1 to jump while in the air is no longer being met, which prevents the player from jumping more than once while in the air.

That is my logic behind the double jump, until next time…cheers!

--

--

No responses yet