#how i accelerate the lerp function?
68 messages · Page 1 of 1 (latest)
there is the 'amount' argument
lerp(0, 10, 0.5)
you can change that 0.5 to be a larger or smaller number.
but he moves slower the closer he is, and faster the farther he is,
this is the nature of lerp.
The alternate is "approach", which is a custom function
function approach(_from, _to, _step) {
return (_from + clamp(_to - _from, -_step, _step));
}
same idea as lerp, but you take the same constant step towards the goal.
red is lerp
blue is approach.
lerp technically never ever reaches the goal, it just gets arbitrarily close.
approach does reach the goal and does not speed up/slow down, but will abruptly stop when it arrives
is exactly this the problem
i dont know how i make this
what's your lerp code?
if distance_to_object(obj_player) <= dist
{
x = lerp(x, obj_player.x, 0.0045)
y = lerp(y, obj_player.y, 0.0045)
}
but if i increase this number the slime will move very much fast
increase it less
hm
(you also don't have to ping me in every reply)
just try numbers out til you're happy. if it's too fast decrease it, if it's too slow increase it
sorry, i'm used to doing this with people on discord
but what was this that you showed to me?
what, approach?
it's just a different way of doing it if you didn't like the "slow down when it's near the player" behavior
since you mentioned it in your question
you put that code in a script
same as lerp
_step you probably want a bigger number tho. it functions the same as walk_spd
got it
thanks
i will test
@chilly knoll Compile Scripts...Error : duplicate script name found gml_Script_approach
you already had an approach script
check through all your scripts
or
ctrl-shift-f, search for Approach
or
just rename the newest approach script to something else, like approach_towards or something
remove this
ah
you don't need to define the vars inside a function
the function is meant to have undefined variables
because then it lets you slot in whatever variables you want later on when you use it
why
script execute
ok
remove that var stuff
no no no no
remove that var stuff
is to execute the aprroach
if distance_to_object(obj_player) <= dist
{
x = lerp(x, obj_player.x, 0.0045)
y = lerp(y, obj_player.y, 0.0045)
}
remember this?
yea
if distance_to_object(obj_player) <= dist
{
x = approach(x, obj_player.x, 0.0045)
y = approach(y, obj_player.y, 0.0045)
}
AAAAAHH i got it
0.0045 is very small here, so you wanna make it bigger
this is what a function does fyi
we get to write our own custom functions that we can use just like the built in ones
cool