How to Create Jump-Through Platforms


How to Create Jump-Through Platforms

The Windy Woods template is a great starting point for your own platformer. 

In this tutorial, you'll create a platform that the player can both jump through and fall through.

Create a new project using the Windy Woods template. You can choose either GML Code or GML Visual:

undefined

You can use your existing Windy Woods project if you already have one.

Room Set-up

Our jump-through platform will be a new object, which we’ll place in the level.

Create a new object and name it obj_jump_through.

undefined

I've put this new object under Objects -> Environment.

Assign it the sprite spr_bridge (Sprites -> Environment -> Blocks).

undefined

New Section in Level

Let’s build a new section in our level that will make use of our jump-through platforms.

Open rm_level_1:

undefined

Select the CollisionTiles layer.

undefined

Select the ‘normal’ auto-tile library on the right-side menu:


undefined

Create some tall walls:

undefined

Select the “Instances layer:

undefined

And place some jump-through platforms between those walls (obj_jump_through).

undefined

Jumping through platform

The project has a script called Collisions, which contains a “check_collision” function.

This function is used for all collision checks for characters, against all tiles and collision objects.

We’ll update this function to take the jump-through platform into account, and to only collide with it when the character is falling.

Open the Collisions script:

undefined

Before the first tilemap_get_at_pixel() call, or the first “Get Tile Index At Pixel” action, add this code:

if (vel_y >= 0)
{
        var _platform = instance_place(x + _move_x, y + _move_y, obj_jump_through)
        if (_platform != noone)
        {
                if (bbox_bottom <= _platform.bbox_top)
                {
                        return true;
                }
        }
}


undefined

This code checks if the character’s velocity is greater than or equal to zero, which means it’s either standing still, or falling down.

It then looks for a collision with obj_jump_through, which is our jump-through platform.

It stores the ID of the platform it finds in the platform variable. The value stored will be noone if no platform was found.

If it found a platform, it will check if the player’s bottom edge is above the platform’s top edge.

This means the player is entirely above the platform, and not halfway through.

In that case, the function returns true, telling the character that a collision was found.

In all other cases, it doesn’t collide with jump-through platforms, so they’re not detected when the character is jumping.

Result

The player can now jump through platforms!

Let’s add an additional feature: when you press S, or down arrow, the player should fall through the platform, making it a “two-way” platform.

Falling Through Platforms

This will happen when the player presses the down arrow.

In obj_player (found under Objects -> Characters -> Player), add Key Press - Down event:

undefined

Here, add the following code:

if (place_meeting(x, y + 1, obj_jump_through))
{
        y += 1;
        grounded = false;
        sprite_index = spr_player_fall;
        image_index = 0;
}

undefined

This code checks if there's a collision with a jump-through platform, just one pixel below the player.

If there is one, it moves the player down by one pixel.

This makes our condition in the check_collision() function false, as the player is not entirely above the platform anymore, making it fall through.

Then it sets grounded to false, as the player is not grounded anymore, and changes the sprite to the fall sprite for the appropriate animation.

Alternate Input

We should also allow this to happen when S is pressed, for players using the WASD keys.

Add the Key Press - S event:

undefined

And add the following code:

event_perform(ev_keypress, vk_down);

undefined

This code calls the Key Press - Down event.

Now, regardless of whether the player pushes Down or S, the same code will run!

This is actually how the player character works for moving left and right as well, if you take a look at those events.

The player can now both jump through and fall through these platforms, using either the down key or the S key:

Read more GameMaker tutorials to build your game.

Happy GameMaking!