A basic platforming tutorial for begginers

Hey guys, my first tutorial, yay!

It's based on a video series I watched in the past to help me get the basics of platforming down, but I intend to explain what each thing does as well as a method of tracking which sprite to show the player.

I'm doing this partly for fun and also as I gave a buggy version of this guide to someone on the forums and feel bad about it.

Here goes.

What you need:
Game Maker (duh), Lite is fine.
Keyboard and Mouse would help aswell

Step 1: Making your basic resources.
Make 2 sprites, both 16x16 boxes.
Call 1 spr_Wall and the other spr_Player (give the player a little face indicating direction or something nice)

Click the 'center' button on spr_Player as we will use this later.
Duplicate spr_Wall, click center on the copy and name it spr_Player_Mask

Now make 2 objects:
obj_Wall: Tick the 'solid' box and set the sprite to spr_Wall
obj_Player: No 'solid' tick in this one. Set the sprite to spr_Player and the mask to spr_Player_Mask

Step 2: Making the platforming basics.
Create a new script and call it scr_Platforming and enter the following. (Don't worry I will explain it as we go)


//Checks if in the air
if place_free(x,y+1)
gravity = 1
//Not in the air
gravity = 0
//Sets Gravity direction to down
gravity_direction = 270

The // bits are comments, they wont run and are handy. If you don't gather what this does from them, it checks if you are in the air, and adds gravity, and removes it when you are not. The last line sets it so the gravity goes towards the bottom of the screen.

Next we want to be able to control the player so enter the following:

//Check if pressing right
if keyboard_check(vk_right) && place_free(x+4,y)
x += 4
//Check if pressing left
if keyboard_check(vk_left) && place_free(x-4,y)
x -= 4

What this bit does is check if you have pressed the left or right keys, and then checks if that place is actually free, before moving you into it.

Jumping is next.

//Checks if up pressed and player is on the ground
if keyboard_check(vk_up) && !place_free(x,y+1)
vspeed = -7

The comments say it all here. The ! means that it is checking the place is NOT free.

Save that script and open up obj_Player. Create a 'step' event and add a code block. In this block we will call the script we just wrote.

Now for the last bit of the basics (yay)
Create a 'collision' event in obj_Player for when it collides with obj_Wall, put a code thing in and enter the following.
//Checks if in the air but block is in the way whilst falling

if vspeed > 0 && !place_free(x,y+vspeed)
//Places on block without errors
//Sets vspeed back to 0
vspeed = 0

That rounds up the basics. Make a room, place obj_Wall down where the floor/ walls should be, drop obj_Player in the middle somewhere (or 2 of them for some luls)
and test it out.

I will edit and add slopes in tomorrow (if I can?) Because I'm sleepy now.

Part 2: Slopes.

With the basics down this is actually fairly easy.
First off, make 2 new sprites called spr_slope_r and spr_slope_l, they will be exactly the same as the wall sprite except cut in half diagonally (make the top half transparent, (should start off that way in gm8.1) easiest way to do this is start with a transparent sprite and then drag a black line from the bottom corner to the top, then use the fill tool on the bottom half.

slope_r should be going up to the right, and slope_l up to the left.

Now we need 2 new objects, that's right, obj_slope_r and obj_slope_l. Make them solid, give them their respective sprites then set their parent object to obj_Wall.

Now for some more code, don't worry it's simple this time.

Go to the part of your code where you put the movement in keyboard_check(vk_left/right)

and change it to the following:

if keyboard_check(vk_right) && place_free(x+4,y+4)

x += 4
y += 4
else if keyboard_check(vk_right) && place_free(x+4,y)
x += 4
else if keyboard_check(vk_right) && place_free(x+4,y-4)
x += 4
y -= 4

Alright, the first if statement checks if there is a a downward slope in front of us. We do this first because if we checked for a normal surface first, it would still come back true and give a really silly effect like falling down stairs.

The second bit should look familiar, it's our original block of code.

The last bit checks if we can move up a slope, in the event we cant proceed normally forward, this goes last because otherwise we would look like we are hopping along instead of walking.

Do this again beneath for vk_left, make sure all the x+4s are changed to x-4s and then test it out.

There may be a few bugs here and there to do with moving onto slopes whilst jumping but they will soon be corrected in part 3.

Part 3: Action and Direction detection, and why.

I wont go too much into the extra code today because I'm sleepy again but I'll explain the idea.

We will use two variables 'movement' and 'facing' in order to tell the game what sprite the player should have, such as jumping, falling, walking and standing and whatever other actions you may have in mind for your game.

Basically we want to make a create event in the player and add the following code.

movement = 'idle'

facing = 'r'

Now I will continue this at some point tomorrow.


Pages: 1
This is a really helpful tutorial:) Thanks alot. There arent't many people who use game maker on this site, but this would be a good tutorial for beginners. Currently on this site there is a Platforming game called Fantasia, it uses similar coding and this could help improve it.

Hopefully you make more in the future.
Haha thanks man, so long as someone gets some use out of it I'll be happy, but I mostly use rpg maker myself and just like to fiddle with gm every now and then.

Anyways, I'll check out Fantasia and get around to finishing this at some point xD
Thanks for putting this up its been really helpful! I was having some problems with the slopes though, my character still just treats it like a square block and if I jump on it, it is as if it's standing on the missing part of the block. Do you know how to fix this?

P.S. I realize I'm posting this almost two years later, just hoping for any kind of help, thanks in advance.
Pages: 1