- Home /
Usage of InverseLerp
Hi,
Can anyone explain how and when does one use InverseLerp ?? I understood Lerp and its usage but i am not able to understand when should one use InverseLerp ??
I used it once for predicting complex rotations in a multiplayer game. The idea was to find out how much I'd have to lerp the remote player on the lovcal machine to arrive at the received network state, then lerp it by double that amount to achieve near-precise rotation prediction.
It was crude, but it worked.
Answer by Wolfram · Jun 17, 2012 at 08:00 PM
I was a bit confused looking at the docs just now, because the explanation is rather terse. But it actually does exactly what it suggests - instead of returning a value between A and B correspondin to the lerping parameter, it returns the lerping parameter if you feed it the value between A and B.
I guess you could use it for a Slider value or something similar: if you know the lowest possible point of your slider is minPixels
, and the highest possible point is maxPixels
, the value returned by
Mathf.InverseLerp(minPixels, maxPixels, currentPixelPositionOfSlider);
is just the "percentage" (in the range between 0..1) of how much your slider is "full".
So to clarify: - Lerp funciton takes a percentage and returns the value in range - InverseLerp function takes a value in range and returns the percentage
Answer by a67_nk · Jun 22, 2017 at 12:19 PM
I know it's not the right place to ask but can you please explain me what is mathf.lerp and how does it work, plz