- Home /
Is it possible to know how 'complete' a lerp operation is?
I'm making a rhythm game based off fnf and one of the aspects is a grading system, where you get given different amounts of points based off how accurate you are. Currently I'm using a regular lerp function, but I heard from one youtube tutorial that you can track how 'complete' a lerp function is. But I've tried it and it does work but it doesn't move at all. Is it possible to know, in a singular number, how 'complete' a lerp function is?
So I'm assu$$anonymous$$g what you are doing is simply doing (0,totalNotes,notesHit)?
Answer by Hellium · May 08, 2021 at 05:51 AM
There are three arguments in Lerp:
The initial / minimum value
The target / maximum value
A factor between 0 and 1
The third factor is how "complete" the Lerp is.
Warning! If you use Lerp as follow currentValue = Lerp(currentValue, targetValue, Time.deltaTime * speed)
, it's not the same.
You can also retrieve this value using InverseLerp
factor = Mathf.InverseLerp(minValue, maxValue, current value);
EDIT: There is no InverseLerp
for Vector3
. The issue here is that your vectors may not be aligned so InverseLerp
would not make sense.
What you could do is to project the "intermediate vector" onto the (start → end) vector. I tested and it seems to work
Vector3 startVector = ...; // ≈ minValue
Vector3 endVector = ...; // ≈ maxValue
Vector3 intermediateVector = ...;
Vector3 projectedVector = Vector3.Project(intermediateVector - startVector, endVector - startVector); // ≈ currentValue
float factor = Mathf.InverseLerp(0, (endVector - startVector).magnitude, projectedVector.magnitude);
aagh forgot to add in some details I'm working with vector3's...