Skip to content
drewmccluskey edited this page Jan 9, 2019 · 5 revisions

lerp

This function will return a percentage of the sum of two inputs

Syntax:

lerp(float a, float b, float amt)
Argument Description
float a The first number to add
float b The second number to add
float amt The percentage to return

Returns: float

Description:

This function will return a value which is the stated percentage of the sum of two input float values. It can be used to predict movement within a program.

Example 1:

float tax = lerp(income, -expenses, 0.1)

This will set float tax to ten percent of net income in a game of finances for example.

Example 2:

float xFuture = lerp(x, x+hspeed, room_speed/2)

This code will set float xFuture to the predicted x position of an object after half a second of gameplay. This can be useful for online games to reduce visual lag as well as for smarter enemy AI.

Back to interpolations

Clone this wiki locally