lerp


Description

With this function you can find the value that equates to the position between two other values for a given percentage. So if you do, for example:

lerp(0, 10, 0.5)

you would get the return value of 5, which is 50% of the input values. You can extrapolate using this function too, by supplying a positive or negative value for the interpolation amount so that doing something like:

lerp(0, 10, 2)

will return a value of 20.


Syntax:

lerp(a, b, amt)


Argument Description
a The first value.
b The second value.
amt The amount to interpolate.


Returns:

Real.


Example:

xx = lerp(x, x + hspeed, room_speed);
yy = lerp(y, y + vspeed, room_speed);

The above code uses the linear interpolation function to predict where an instance would have moved to after one second of game time.