Hello,
I'm trying to code movement for the player object inside a game with the following code:
'Approach; is a script I saw from a youtuber and it goes as follows:
When I try to run the game it turns up an error that says Code Error DoSub :1: undefined value. Is there something that I am missing? I am following a youtube tutorial and yet it doesn't work for me
I'm trying to code movement for the player object inside a game with the following code:
GML:
var dir = key_right - key_left;
hsp += dir * hsp_acc;
if (dir == 0)
{
var hsp_fric_final = hsp_fric_ground;
if (!onground) hsp_fric_final = hsp_fric_air;
hsp = Approach(hsp,0,hsp_fric_final);
}
hsp = clamp(hsp,-hsp_walk, hsp_walk);
Code:
///Approach (a,b,amount)
/// @description Approach (a,b,amount)
/// @param a
/// @param b
/// @param amount
/// Moves "a" towards "b" by "amount" and returns the result
/// Does not overshoot "b"
if (argument0 < argument1)
{
argument0 += argument2;
if (argument0 > argument1)
return argument1;
}
else
{
argument0 -= argument2;
if (argument0 < argument1)
return argument1;
}
return argument0;