Game Maker Studio: Platformer Slopes Tutorial

[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 –


Xem thêm bài viết khác:

Article Categories:


  • Great tutorial mate thumbs up!

    Spirit Engine Studios June 28, 2020 6:03 pm Reply
  • 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

    Kai Proton June 28, 2020 6:03 pm Reply
  • While I'm not using gamemaker specifically this does help a lot. Thanks!

    Keith Blagden June 28, 2020 6:03 pm Reply
  • How would you make this work with the built in functions hspeed and vspeed because I use friction

    chris rosa June 28, 2020 6:03 pm Reply
  • Thanks very much for this. I have a question though. What way do you create your ground?
    This method only seems to work for me if I draw the ground pixel by pixel which is not very efficient. An if I angle larger objects to make a slope the collision still makes a box shape.

    Red June 28, 2020 6:03 pm Reply
  • super choppy for pixellated textures. Why is this so difficult…

    Quinton LeBlanc June 28, 2020 6:03 pm Reply
  • The steepness in abs(1*hsp) is = dtan(steepness) where steepness is in degrees

    Mason Thompsen June 28, 2020 6:03 pm Reply
  • Doesn't work for GM7, just crashes.

    Admiral Jezza June 28, 2020 6:03 pm Reply
  • Shaun you saved my day today.

    Kyle Askew June 28, 2020 6:03 pm Reply
  • Ok for anyone reading this, this tutorial IS NOT BAD. It's actually one of the tutorials that worked for my game. It's really simple and if you have a good idea of how place_meeting with angles and know moving with vspeed/hspeed/x/y, you'll find this to be very simple. It's also very smooth. The issue for this tutorial is that he didn't code a way to have smooth movement going down. Now that's not a problem if you look in the comments and copy some of the premade down slope codes people commented. I had to do it because I couldn't figure out how to do this without my character freaking out and going into the ground. Thank you Shaun for the tutorial and everyone who commented code for going down slopes. It really helped me and hope people in the future can have a easier time.

    HarveyTJ03 June 28, 2020 6:03 pm Reply
  • 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!

    Standard_Nova June 28, 2020 6:03 pm Reply
  • 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

    Max Shtefec June 28, 2020 6:03 pm Reply
  • How do I have it change to the run sprite when on slopes instead of idle sprite?

    Hackmi HaKMI June 28, 2020 6:03 pm Reply
  • 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?

    OctoMan June 28, 2020 6:03 pm Reply
  • 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.

    Necromedes June 28, 2020 6:03 pm Reply
  • Mine only works when I put in yplus <= abs (number greater than or equal to 2 * hsp). someone can help me?

    david f fortes meireles June 28, 2020 6:03 pm Reply
  • Nice tutorial, I was able to adapt it to my existing engine!
    Next up, I have to code going down slopes smoothly!

    PleaseDontSubscribe June 28, 2020 6:03 pm Reply
  • Hi guy! How can i fix the shaking problem? When i walk on slopes player shake is not a smooth moving. Thanks!

    claudiuboy83 June 28, 2020 6:03 pm Reply
  • 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?

    jacob lawson June 28, 2020 6:03 pm Reply
  • You said that you can also reverse the code for walking down, I really need this.
    How can I do this?

    Gaming Maniacs June 28, 2020 6:03 pm Reply
  • 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

    CrossWindCrucible June 28, 2020 6:03 pm Reply
  • why is there a BE-BOOP

    Bmoney64 June 28, 2020 6:03 pm Reply
  • 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.

    FBI Agent 69 June 28, 2020 6:03 pm Reply
  • 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?

    Mr Zuchis June 28, 2020 6:03 pm Reply
  • Brilliant! So simple.

    Kyle Askew June 28, 2020 6:03 pm Reply
  • 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.

    Peter Kaufinger June 28, 2020 6:03 pm Reply
  • 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.

    Bramwell Simpson June 28, 2020 6:03 pm Reply
  • 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.

    Hand-Drawn Animations June 28, 2020 6:03 pm Reply
  • 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))

    Matthias June 28, 2020 6:03 pm Reply
  • 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?

    Taylor Bramble June 28, 2020 6:03 pm Reply
  • Great work as usual.

    RealSolid_Snake June 28, 2020 6:03 pm Reply
  • 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;}}

    Avyrra June 28, 2020 6:03 pm Reply

    Gabriel Crowe June 28, 2020 6:03 pm Reply
  • 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.

    MidoriMushrooms June 28, 2020 6:03 pm Reply
  • 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.

    Dslyecix June 28, 2020 6:03 pm Reply
  • This code seems unresponsive to the new platformer video. Someone please help!

    Cody Gutridge June 28, 2020 6:03 pm Reply
  • 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.

    Herpy McDerpface June 28, 2020 6:03 pm Reply
  • 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.

    Purianite June 28, 2020 6:03 pm Reply
    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;

    LunarFurorGames June 28, 2020 6:03 pm Reply
  • Beeboop?

    mushroomdude123 June 28, 2020 6:03 pm Reply
  • "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.

    kenshokram June 28, 2020 6:03 pm Reply
  • 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 😛

    ShaolinMonkster June 28, 2020 6:03 pm Reply
  • 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.

    Ádám Pajor June 28, 2020 6:03 pm Reply

Leave a Comment

Your email address will not be published. Required fields are marked *