Game Maker Studio: Platformer Slopes Tutorial -

Game Maker Studio: Platformer Slopes Tutorial

Shaun Spalding
Views: 75630
Like: 882
[project link coming soon, raw code changes for horizontal collision available here: ]

This has been requested for a very long time. So I thought I’d finally put something together for it. I’ve never done slopes before but this is how I would approach doing them. This video is a detailed explanation of a short adjustment to the In Depth Platformer () tutorial that will allow your character to walk up slopes, curves and hills.

Buy my game, Another Perspective!
Read my blog!
Follow my twitters!

Intro clip animation by Hassan Otsmane Elhaou –
Intro music by Matthew Harrington –


  1. Yeah but what is par_wall? Or where I can find a video about it?

  2. i did this code and suddenly my character walks through the sides of my square blocks now which he used to stop upon collision. how did this change that?

  3. this code fucked with my collision of basic blocks.

  4. What would be the best solution to handle slopes that you may not necessary want to climb but you could walk next to them?
    I mean, a different type of slope that you go next to it, but if you press up while you're next to it, you climb it. So you would have the choice to go forward straight ignoring the slope or climb up.

  5. So guys if you change the 1*hsp inside the abs(), and give it a constant number like 5, many of your problems will be solved 😛

  6. "Project link coming soon" 3 years ago. I feel like making all the new sprites and objects for the slopes on the terrain is confusing, you didn't include making the terrain in any video before this.

    This isn't "perfect" but it works most of the time. For best results use a mask image that is an od number of pixels wide, (depending on how you do facing logic) to ensure that turning around on a slope works correctly, I've also found that using a square and not rounded mask works best here also

    if (place_meeting(x+horSpeed_final,y,objWall)){
    yPlus = 0;
    while(place_meeting(x+horSpeed_final,y-yPlus,objWall) && yPlus <= abs(1*horSpeed_final)){
    yPlus +=1;
    if(place_meeting(x+horSpeed_final, y-yPlus,objWall)){
    x += sign(horSpeed_final);
    horSpeed_final = 0;
    horSpeed = 0;
    y -= yPlus;
    yMinus = 0;
    while(!place_meeting(x+horSpeed_final,y+yMinus,objWall) && yMinus <= abs(1*horSpeed_final)){
    yMinus +=1;
    //still not sure why exactly this needs to be here, but it does for math reasons.
    yMinus -= 1;

    //if there is a place of meeting at yMinus (speed+1) but not at yMinus (speed) AND we're already on the ground, move down
    if(place_meeting(x+horSpeed_final, round(y+yMinus)+1,objWall) && !place_meeting(x+horSpeed_final, round(y+yMinus),objWall) && place_meeting(x, y+1,objWall)) {
    y = round(y+yMinus);
    x += horSpeed_final;

    if (vertSpeed < vertSpeed_max) {
    vertSpeed += grav;
    if (place_meeting(x,y+1,objWall)){
    if(input_btn1 && !input_down){
    vertSpeed = -jumpSpeed;
    if(vertSpeed < 0) && (!input_btn1_held){
    vertSpeed = max(vertSpeed,-jumpSpeed/2)

    if (place_meeting(x,y+vertSpeed,objWall)){
    y += sign(vertSpeed);
    vertSpeed = 0;
    y += vertSpeed;

  8. Did you ever come up with a solution that allows for descending slopes as well?

    I was going to try and roll one with a for loop, but I'm wondering if you might have any official adjustments to this already.

  9. If anyone wants an easy solution to walking down slopes, create a unique parent for slopes ex: par_slope, and set it's parent as wall. Set your slope object's parent as par_slope.

    Then, all you have to do is crank up the gravity super high when you're touching a par_slope, and have it reset to regular gravity both when you jump and when you touch par_wall. That way the only time gravity is super high is when you're touching the slope and when you reach the bottom to the ground and hit a floor (par_wall) it goes back to normal. This solved it for me and I spent all day trying to fix it. My regular gravity was 1.5 and it's 30 on slopes. I run perfectly down it and it doesn't even mess up my run animation anymore. And I can jump from a slope no problem since the code for jumping comes before the code for slope super gravity.


    if (key_jump) && (jumps > 0)
    jumps -= 1;
    vsp = -jumpheight;

    grav = 1.5;

    if place_meeting(x,bbox_bottom,par_slope) && (grounded == 1) grav = 30;

    And then I just put "grav = 1.5" in my vert collision code.

  10. This code seems unresponsive to the new platformer video. Someone please help!

  11. Why are you people having so much trouble thinking through the logic of how to implement this going down slopes? Do you really need to be hand fed every aspect of overcoming a problem? Just think about it:

    The problem is you're changing to your 'fall' animation the instant your character is in the air. Instead, you want – if your character is newly in the air – to do the inverse of this "check if this space is free", just downwards. If your character steps of a pixel ledge, is the pixel below them ground? If not, is the pixel below that ground? And so on. Until you've exceeded whatever depth you decide is the maximum "slope height", you don't fall, you merely move the object downwards to be touching the ground again.

    If you set this sticky height to 3 pixels, then any slope that changes at a 3:1 ratio your character will slide down without changing animations. Anything deeper than that, and you have them 'fall' until they hit the ground your regular way.

    Just because you can't "slap the upward code in backwards to get it to work down" doesn't mean this is a bad tutorial. It shows you the logical steps to take, the way to think about the problem, so as to get the result you want. You're programming a game, you HAVE to use your heads and logically work through the issue at hand.

  12. I tried to stick this in my engine (I'm using the new platforming one, not the old one) and for some reason now my map has become a giant trampoline…what the hell is going on?
    Edit: Nevermind, I fixed it. There was a } out of place, it was causing havoc. Also declaring the variable within the loop gives an error. I had to do it in the create event, it still functions like it should.

  13. Took me awhile, but try adding the following code in between the horizontal movement and vertical movement code for downward slopes.

    if !place_meeting(x,y,par_wall) && vsp >= 0 && place_meeting(x,y+2+abs(hsp),par_wall)
    {while(!place_meeting(x,y+1,par_wall)) {y += 1;}}

  14. For whatever reason, whenever I try this it works only with rectangle bounding boxes. If I make an angled sprite and use precise collision checking so its a sloped mask, my character walks right through. If i change it to rectangle, it then realizes it's a collision and will either stop at it if it's to tall, or will work correctly if its short enough.
    Does anyone know why this could be?

  15. I ran into the issue where the player would go "up down up" really fast when he moves one pixel up to the slope.
    You can fix it by adding yplus to the vertical collision if statement. (you need to initialize yplus first in the creation code otherwise you get an error)

    //Vertical collission
    if (place_meeting(x,y+vsp+yplus,par_wall))

  16. When I Use Slopes This Works GREAT!!! But NOW Whenever I Run Into A Block(higher than a slope), My Game Freezes. I do NOT know why.

  17. I have separate object for the slope and the code is completely unresponsive to the object. Can anyone help?
    I followed this tutorial and the newer basic platformer tutorial.

  18. I have a question, I;m making a Tank multiplayer game and it can only move forward and backwards, it can turn – just bear in mind it turns like a tank. Anyhow, I want to be able to move it grammatically diagonally, like while moving forward you turn so it begins to turn…I'm not sure I can check collision with the method of using direction and speed vars. I thought I could still do this by finding the slope based on the direction the tank is, input that into sine and maybe do some other trigonometry and thus be able to make the tank slide along the wall. If anyone has any ideas on this I'd greatly appreciate it.

  19. Can someone Heçlp?
    How are you doing these hills? If I rotate my wall objects to use it as a hill the character doesn't move up on them, it is treated as a straight wall, I've tried to handle this but it doesn't work, does someone know what to do?

  20. I have a problem where if I jump onto a slope, or if I go halfway down and try to go back up my player doesn't move, I have to start at the bottom of the slope or he will not move up.

  21. Hello! I know this is from 2013, but I was wondering if there could be a tutorial about automatically falling/sliding down slopes if they're too steep? For instance, you could fall onto that steep slope you couldn't get up, leaving only one option: going down. But it looked a little strange that you could stop suddenly on such a steep slope. It'd be cool to be able to get sliding down slopes to work

  22. You said that you can also reverse the code for walking down, I really need this.
    How can I do this?

  23. I am having difficulties with the upaward slope code causing my sprite to jitter uncontrolably and preventing the player from jumping. Does anyone have a solution?

  24. Hi guy! How can i fix the shaking problem? When i walk on slopes player shake is not a smooth moving. Thanks!

  25. Nice tutorial, I was able to adapt it to my existing engine!
    Next up, I have to code going down slopes smoothly!

  26. Mine only works when I put in yplus <= abs (number greater than or equal to 2 * hsp). someone can help me?

  27. I suggest remaking this video at some point. You reiterate the same things several times in a row and it gets a bit tiresome. You get the point across well but some people may not want to here the same explanation over and over again. If they don't get it right away, that's what the time scroll bar on the video is for. Just my opinion.

  28. So, copying your code exactly (and I have triple checked), I'm unable to walk up even 1 pixel, can anyone try to help me please?

  29. How do I have it change to the run sprite when on slopes instead of idle sprite?

  30. i can't understand, in you tree objects you can a obj_slope and obj_wall, and see also the par_wall, whats is that? is empty object? or that is a colection of object (obj_wall and slope)? in the code only use par_wall for the collision check

  31. I've found that in the absence of slopes (where the only geometry the player interacts with are square walls) this technique adds a kind of "mantling" mechanic, where if you jump for a platform, but hit its vertical edge a few pixels below the corner, the player is boosted up to the top surface of said platform. It feels as though it smoothens out fast platforming gameplay. Thanks for the tutorial Shaun!

  32. The steepness in abs(1*hsp) is = dtan(steepness) where steepness is in degrees

  33. How would you make this work with the built in functions hspeed and vspeed because I use friction

  34. While I'm not using gamemaker specifically this does help a lot. Thanks!

  35. I Love you tutorials, the times Ive come back over and over, because Ive started to write something and forgot how it works, and needed a refresher… brilll

  36. Hey Shaun, just wanted to say that I'm grateful you've created these GameMaker tutorials for us! Please continue to inspire as you do, we all appreciate your work! God bless

  37. I think i'm the most recent commentor on this video: Can somebody please to GMS2? I need it for my upcoming Indie game.

  38. What would be a good way to code the player sliding down slopes that they can't walk up/down? Currently, this code allows the player to stand on the pixels of steep slopes.

Leave a Reply

Your email address will not be published.