lerp

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

Syntax:

GML Code Example

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:

GML Code 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:

GML Code Example

lerp(0, 10, 2)
 

will return a value of 20.


Example:

GML Code 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.





No Examples Submitted

Does this page need better examples? Be the first to Submit

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here