lerp() - leiget/Godot_FPC_Base GitHub Wiki
βlerp()β is the linear interpolation function. The first argument is the βfromβ variable and the second is the βtoβ variable. The third argument is the βweightβ, using a normalized value, that you want to interpolate between the two.
As an example, letβs say we have a βlerp()β function that looks like this:
Result = lerp( 0.5 , 1.5 , 0.5)
βResultβ will equal β1.0β. This is because the third argument, called the βweightβ, is β0.5β. And since this is a normalized value, what it really means is β50%β.
Since β50%β is halfway between β0%β and β100%β, that means that we want to find whatβs halfway through β0.5β and β1.5β. As you probably already figured out itβs β1.0β.
Another way of looking at it is by this formula:
Result = ( from + ( weight * ( to β from ) ) )
And in real numbers, according to our example:
Result = ( 0.5 + ( 0.5 * (1.5 β 0.5) ) ) = 1.0
And if we were to have a weight of β0.25β:
Result = ( 0.5 + ( 0.25 * (1.5 β 0.5) ) ) = 0.75
And if this was visualized:
It would look like this. Of course, you can just use βlerp()β without all the manual math, but itβs helpful to have an idea of whatβs going on under the hood.
You can also use a βpow()β function, explained in the next chapter, as the weight argument to get a non-linear result.