The Windy Woods template is a great starting point for your own platformer.
In this tutorial, we'll add wall-jumping to the game.
Create a new project using the Windy Woods template. You can choose either GML Code or GML Visual:
You can use your existing Windy Woods project if you already have one.
Level Set-Up
Let's add a small wall-jumping section in the first level for testing.
Open rm_level_1.
Select the "CollisionTiles" layer.
On the right, a new menu will open.
Under “Libraries”, choose the “normal” auto-tile library.
Add some walls for the player to jump off of:
If you run the game now, the player won't be able to climb or jump off of any of these walls:
Let’s fix that!
How to Stick to Walls in Windy Woods?
The player should first stick to a wall, as long as you hold left/right towards it.
Open obj_player's Create event, and add the following code at the end:
wall_direction = 0;
wall_jump_force = 12;
wall_jumping = false;
This code initializes the variables we need for our wall jump.
wall_direction tells us if the player is sticking to a wall, and where that wall is.
It'll be 0 when not sticking to the wall, 1 when sticking to a wall on the right, and -1 when sticking to a wall on the left.
wall_jump_force is the horizontal jumping force applied when jumping from a wall.
wall_jumping will be set to true for a brief period after jumping from a wall, and will be false at other times. This way we can know if the player has just wall-jumped or not.
Sticking Left
Open obj_player's Key Down - Left event, and add the following code at the top of the event.
if (check_collision(-1, 0))
{
wall_direction = -1;
alarm[1] = 10;
}
It then sets Alarm 1 to run after 10 frames, which will reset the player’s wall jumping state. (That event doesn't exist yet - we'll make it soon.)
Stop Right There
When the player has just wall jumped, we don't want them to change directions. This requires a simple change.
In the same event, there's a condition that checks if the player is in knockback, which then exits the event.
Add ‘or wall_jumping’ to the following If Expression so the event exits if the player is wall jumping.
if (in_knockback or wall_jumping)
{
exit;
}
This means the player can’t move if they're wall jumping.
Sticking Right
Now, repeat the last two steps in the Key Down - Right event, but replace -1 with 1.
if (check_collision(1, 0))
{
wall_direction = 1;
alarm[1] = 10;
}
Don't forget to add ‘or wall_jumping’ into the next condition.
Alarm to reset state
Create an Alarm 1 event:
And add the following code in it:
wall_direction = 0;
This will reset wall_direction to 0, which means the player isn't wall jumping, and they can move again.
Slow Down Gravity
While the player sticks to a wall, we want them to fall slower.
Next, inherit the Begin Step event.
Add the following code after event_inherited() or the Call Parent Event action:
if (wall_direction != 0)
{
if (vel_y > 3)
{
vel_y = 3;
}
}
This code reduces the player's Y velocity to 3, slowing its fall, if wall_direction is not 0 (i.e. the player is next to a wall and is pushing left or right).
If we run the game now, the player can stick to the wall, but can't jump off it yet.
Jumping from a Wall
Open obj_player's Key Press - Space event.
At the top of the event, add the following code:
if (!grounded)
{
if (wall_direction != 0)
{
vel_y = -jump_speed;
vel_x = wall_jump_force * wall_direction * -1;
sprite_index = spr_player_jump;
image_index = 0;
grounded = false;
wall_jumping = true;
alarm[2] = 30;
exit;
}
}
This code checks if the player is in mid-air and if wall_direction equals something other than 0.
If both of these requirements are met, we know that the player is sticking to a wall, and because of the event, that they're pressing Space. It’s wall-jumpin’ time.
We set the player's x and y speed, basing the x speed on the wall_direction, multiplied by -1 so the player jumps in the opposite direction of the wall.
Then it changes the player's sprite to the jumping one, sets grounded to false, and wall_jumping to true.
wall_jumping should be reset after half a second, so we set Alarm 2 to 30. We'll create this event soon.
Finally, it exits the event, so the normal jumping logic doesn’t run.
Reset Wall Jump
Create an Alarm 2 event:
And add the following code to reset wall_jumping to false.
wall_jumping = false;
Here we go!
The player can now wall jump.
You can now make new sections in your levels that use wall jumping, and hide secrets behind clever wall-jumps.
Read more GameMaker tutorials to build your game.
Happy GameMaking!