Double Jump

Written by Luke Harrison 2007

In this tutorial you will learn how to make your character perform a double jump.


Summary

  1. Set Variables on the Character Object
  2. Make the Character Object Jump
  3. Set Collision Event with the Walls

Download Example


Before you Start

You will need a platform game engine which includes a character that is pulled down by gravity and a wall.

If you don't have this, follow this tutorial or download the example, Platform Movement


Set Variables on the Character Object

First, we need to set some variables, we need to set, how high the character can jump the first time, how high they can jump the second and a variable to say if they can do the double jump or not.

  • Open the Object Properties of the Character Object.
  • Open the Create Event, if there isn't one, Add a Create Event.

  • Add the, Set Variable Action from the Control Tab.
    • Set Variable as, can_double
    • Set Value as, true

The following two are optional but make tweaking the double jump easier.

  • Add another, Set Variable Action from the Control Tab.
    • Set Variable as, first_jump_height
    • Set Value as, -10

  • Add one more, Set Variable Action from the Control Tab.
    • Set Variable as, second_jump_height
    • Set Value as, -8

The reason for putting a minus number is because we want the character to move up on the y axis, negative on the y axis is up.


Make the Character Object Jump

  • Open the Key Press Up Event (Your Jump Key Event)

The original jump script, checks that the character is on the ground, if it is, it jumps. Because we want to do a double jump, we need to do some actions when the character is in the air and the user presses jump again, we can use an else statement for this.

First, we have to check that the character is on the ground before allowing it to jump into the air for the first time.

  • Add the, If there is a Collision at Position Action.
    • Set Y as, 1.
    • Tick Relative.

This will check that the character is on the ground before doing anything else. To make the character start moving up, you have to change the vspeed to the value of the first_jump_height variable. This will perform the first jump.

  • Add the, Set Vertical Speed Action.
    • Set Vert Speed as, first_jump_height

The first jump is performed if the character is on the ground when the jump button is pressed. To check that the character is on the ground, the If Collision at Position statement is used. To check the character is in the air to do the second jump, the Else block is used in conjunction with the Collision at Position statement. If the character is NOT in the air, the actions after the Else block will be performed.

  • Add the, Else Statement Action, from the Control Tab.
    • Add this AFTER the original Statement and Set vspeed Action

First, before we do anything regarding the double jump, we want to check if we can, this is stored in the can_double variable, we need to check the value of this is true.

  • Add the, If Variable Has a Value Statement Action, from the Control Tab.
    • Set the Variable as, can_double
    • Set the Value as, truel

This will check if the can_double variable is true.

Because we are going to do more than one action after the IF statement, we need to use the Start and End blocks.

  • Add the, Start Block Action, from the Control Tab.
    • Add this AFTER the IF statement.

If can_double is true, we want to set it to false so you can’t do a triple jump then perform the second jump.

  • Add the, Set Variable Action from the Control Tab.
    • Set Variable as, can_double
    • Set Value as, false

This sets the variable to false, this will prevent the player doing any further jumps.

  • Add the, Set the Vertical Speed Action, from the Move Tab.
    • Set Vert Speed as, second_jump_height

  • Add the, End Block Action, from the Control Tab.
    • Add this at the end of the Actions.

Now we can control when to perform a second jump and prevent any further, we need to reset the can_double variable back to true, we will do this when the character hits the ground.


Set Collision Event with the Walls

Open the Collision Event with the Wall Object.

What we want to do here is check if the floor is below the character, we will use the If There is a Collision at Position Statement.

At the end of the actions,

  • Add the, If There is Collision at Position Action, from the Control Tab.
    • Set Y as, 1
    • Tick Relative

This will check for a floor below the character.

  • Add the, Set Variable Action from the Control Tab.
    • Set Variable as, can_double
    • Set Value as, true

This will reset the can_double value back to true. Now this code will detect when the character hits the wall, it will then check, If the wall is below the character, if it is, it will set can_double back to true, this will allow the user to do a double jump again.