1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GML Problem to clim stairs

Discussion in 'Programming' started by Tarte, Feb 10, 2019.

  1. Tarte

    Tarte Member

    Joined:
    Jan 10, 2019
    Posts:
    30
    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):
     

    Attached Files:

  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,101
    What code do you have to climb the first step, and does it even work?
     
  3. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    626
    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.
     
  4. Bayesian

    Bayesian Member

    Joined:
    Sep 13, 2016
    Posts:
    390

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice