#how i accelerate the lerp function?

68 messages · Page 1 of 1 (latest)

cold beacon
#

I want to make a slime follow me via the lerp function (which I know isn't the most sophisticated way to do it, but it might work (I hope)). So I put his lerp on the player, but he moves slower the closer he is, and faster the farther he is, I wanted to know a way to increase and decrease the speed of the lerp

verbal briar
#

there is the 'amount' argument
lerp(0, 10, 0.5)

you can change that 0.5 to be a larger or smaller number.

chilly knoll
#

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

cold beacon
#

i dont know how i make this

chilly knoll
#

what's your lerp code?

cold beacon
chilly knoll
#

increase this number

cold beacon
# chilly knoll

but if i increase this number the slime will move very much fast

chilly knoll
#

increase it less

cold beacon
#

hm

chilly knoll
#

0.00451

#

is a tiny increase, for example

cold beacon
#

i putted 0.005

chilly knoll
#

(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

cold beacon
#

sorry, i'm used to doing this with people on discord

#

but what was this that you showed to me?

chilly knoll
#

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

cold beacon
#

ummm

#

but what is the value of _from, _to and _step?

chilly knoll
#

you put that code in a script

chilly knoll
#

_step you probably want a bigger number tho. it functions the same as walk_spd

cold beacon
#

got it

#

thanks

#

i will test

#

@chilly knoll Compile Scripts...Error : duplicate script name found gml_Script_approach

chilly knoll
#

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

cold beacon
#

ok

chilly knoll
#

can i see the slime script?

#

just...scooch that error message to the side?

cold beacon
chilly knoll
#

remove this

cold beacon
#

ah

chilly knoll
#

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

cold beacon
#

really

#

the slime isn't going to the player

chilly knoll
#

can i see your code

#

where you used approach instead of lerp

cold beacon
chilly knoll
#

why

#

script execute

#

ok

#

remove that var stuff

#

no no no no

#

remove that var stuff

cold beacon
chilly knoll
#
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?

cold beacon
#

yea

chilly knoll
#
if distance_to_object(obj_player) <= dist
{
    x = approach(x, obj_player.x, 0.0045)
    y = approach(y, obj_player.y, 0.0045)
}
cold beacon
#

AAAAAHH i got it

chilly knoll
#

0.0045 is very small here, so you wanna make it bigger

chilly knoll
cold beacon
#

cool