• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Problem to clim stairs

T

Tarte

Guest
Hi ! I have a problem climbing up stairs to my character. I wish that when he moves forward and touches the first step, he moves and goes on; so on until the last. Small diagram (Do not judge my talents of drawings lol):
 

Attachments

Bentley

Member
A simple way (incomplete code):
Code:
repeat (abs(hspd))
{
    if (place_meeting(x + sign(hspd), y, obj_stair) && !place_meeting(x + sign(hspd), y - 1, obj_stair))
    {
        x += sign(hspd)
        y -= 1;
    }
    else if (!place_meeting(x + sign(hspd), y, obj_stair))
    {
        x += sign(hspd);
    }
}
For moving down stairs change it from y - 1 to y + 1. For 2 pixel high stairs, change it from y - 1 to y - 2. If the stairs vary in height you can use a loop to measure how many pixels are on top of the pixel ahead.
 
Top