lerp

Returns the linear interpolation of two input values by the given amount.

Syntax:

lerp(a, b, amt)


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


Returns: Real.


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.


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.


Back: Real Number Functions
Next: clamp
© Copyright YoYo Games Ltd. 2018 All Rights Reserved