What is range_lerp() ? What are it's function ?
Best Answer

Megalomaniak Posts: 4,173
from http://docs.godotengine.org/ko/latest/classes/class_@gdscript.html#classgdscriptrangelerp
Maps a value from range [istart, istop] to [ostart, ostop].
range_lerp(75, 0, 100, 1, 1) # returns 0.5
And it was added in this commit:
https://github.com/godotengine/godot/commit/d28da86f9ff5a70284e4a2078fa08867d4858a57
OK, so lets look at the above example again:
range_lerp(75, 0, 100, 1, 1) # returns 0.5
The 75 is the integer value plugged into it, and then two ranges are given to it. If we look at the ranges given, 0 to 100 and 1 to 1 here are stated to be equivalent so the input of 75 is effectively then interpreted as 0.5(since that is three fourths, or 75 percent of the way linearly from 1 to 1) which is the value returned by the function.
As for the term
lerp
, it is short for linear interpolation.
Answers
And it was added in this commit:
https://github.com/godotengine/godot/commit/d28da86f9ff5a70284e4a2078fa08867d4858a57
OK, so lets look at the above example again:
range_lerp(75, 0, 100, 1, 1) # returns 0.5
The 75 is the integer value plugged into it, and then two ranges are given to it. If we look at the ranges given, 0 to 100 and 1 to 1 here are stated to be equivalent so the input of 75 is effectively then interpreted as 0.5(since that is three fourths, or 75 percent of the way linearly from 1 to 1) which is the value returned by the function.
As for the term
lerp
, it is short for linear interpolation.Would it be too much to ask for someone to share what range_lerp would look like in mathematical notation?
Imho, much better name for range_lerp would be remap. Because it remaps the value from one min/max range to another.
Math is rather simple:
while lerp and inverse_lerp are:
Thankyou @xyz, I think
by
you meant
@Erich_L Yep, good catch! Corrected it now.
@xyz It really isn't that complicated but it was a bit much for my brain to chew on, so thanks again this helped me a lot. Also, interestingly, even thought I have min1 and max2 set to zero and therefore the equation can be simplified significantly, I found that continuing to use
range_lerp()
was five percent faster than the simplified version.Sure. It's always better to let native code do the grunt work. Adding two numbers in native code is much faster than doing so in the script.