Approach function not working GMS2

Discussion in 'Programming' started by tomsonite, Mar 14, 2019 at 10:36 PM.

  1. tomsonite

    tomsonite Member

    Joined:
    Feb 24, 2019
    Posts:
    2
    I tried typing in the approach function for my player object, only for it to be recognized as a variable and turn purple. I put this in my player object's step event under horizontal movement:

    //Calculate Horizontal Movement
    var dir = key_right - key_left;
    hsp += dir * hsp_acc;
    if (dir == 0)
    {
    var hsp_fric_final = hsp_fric_ground;
    if (longround) hsp_fric_final = hsp_fric_air;
    hsp = Approach(hsp,0,hsp_fric_final);
    }
    hsp = clamp(hsp,-hsp_walk,hsp_walk);


    If anyone knows why it won't turn orange I'd appreciate it!
     

    Attached Files:

  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,572
    Approach isn't a built in function. You have to code it yourself. It is this.

    Code:
    
    /// @description scr_approach(start, end, shift);
    /// @function scr_approach
    /// @param start
    /// @param end
    /// @param shift
    
    if (argument[0] < argument[1]) {
       return min(argument[0] + argument[2], argument[1]);
    } else {
       return max(argument[0] - argument[2], argument[1]);
    }
    
    
     
  3. tomsonite

    tomsonite Member

    Joined:
    Feb 24, 2019
    Posts:
    2
    Ah that makes much more sense. Thanks for the help!
     

    Attached Files:

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