Lerps are the absolute BEST, they account for like 50% of most all my logic, use them EVERYWHERE.
I created my own custom lerps that are extremely powerful that I call "RescaleLerp" if anyone wants to give them a go...
(now that I think about it, I should have called them NomralizedLerp, but whatever)
public static float RescaleLerp(float value, float zeroValue, float oneValue = 1f)
{
if (zeroValue == oneValue) return 0f;
float t = (value - zeroValue) / (oneValue - zeroValue);
return Mathf.Clamp01(t);
}
Basically all it does is you feed it a value, and you tell it at what value it should be set to zero and at what value it should be fully set in at 1 and it just clamps it out from there on out.
So let's say you want something to be more powerful the closer it is to the player like a radiance damage effect you could set the damage fallout with this simple logic:
var startDistance = 1; //distance at which it's 1
var fullRange = 3; //distance at which it's 0
var distanceLerp = zz.RescaleLerp(distanceToPlayer, fullRange, startDistance);
So in this instance you want the higher 1 value to be at the lower value, so you plug in the smaller distance of 1 as the oneValue, and 3 as the zeroValue and it just spits out the correct strenght of your damage falloff.
You don't have to worry about positive or negative, and it just works no matter if the start value is lower or higher than the end value.
Super powerful for a quick and effecient means of creating a "set in" based on a start point and end point.
And once you have that logic you can extend it to transition between a low value and a high value rather than just a 0 to 1 range
public static float LowHighRescaleLerp(float lerpValue, float lowLerp, float maxLerp, float lowValue, float highValue)
{
return Lerp(lowValue, highValue, RescaleLerp(lerpValue, lowLerp, maxLerp));
}
This logic becomes incredibly powerful for gameplay systems where you need things to sorta "set in" or fall off, like little sublte movement touches after you attack or state change blendings based on durations following an event.
I know none of this is mind blowingly complex to do through other means, but it just greatly simplifies a very repetitive we need as system designers to just have something set in or fall off over a specific value range.