This utility was developed for my game Atomic Space Command. Check it out: http://atomicspacecommand.net
In order to simplify and make lerping across a game uniform use this utility. Here's how to use it and then we'll explain the different methods.
To properly lerp with this tool you will need to declare 4 variables:
private float _lerpTime = 5f;
private float _lerpValue = 0.0f;
private bool _shouldLerp;
private string _lerpRequestGuid = string.Empty;
Next you will need to write a method that will create a lerp request:
private void SetLerpMoveRequest ()
{
// Setup a Lerp Request
_shouldLerp = true;
if (string.IsNullOrEmpty (_lerpRequestGuid)) {
_lerpRequestGuid = TBLerp.AddLerpRequestor (_lerpTime);
} else {
// Remove the old requestor first
TBLerp.RemoveLerpRequestor (_lerpRequestGuid);
_lerpRequestGuid = TBLerp.AddLerpRequestor (_lerpTime);
}
}
Then you will need to write a method that will burn the lerp down and set the animations:
private void LerpMoveAnimation ()
{
float perc = TBLerp.LerpSmootherStep (_lerpRequestGuid);
if (perc == 1f) {
_shouldThrustLerp = false;
TBLerp.RemoveLerpRequestor (_lerpRequestGuid);
}
this.transform.localPosition = Vector3.Lerp (_startPos, _endPos, perc);
}
Finally you will need to add a call to the burn down method from the update loop:
private void Update ()
{
// Lerp the engine activity
if (_shouldLerp) {
LerpCurrentPowerAnimation ();
}
}
- LerpNoEasing
- LerpEaseOut
- LerpEaseIn
- LerpExponential
- LerpSmoothStep
- LerpSmootherStep
This is a standard linear lerp with no acceleration. Things start and stop at a constant.
This is performed using sinerp
This is performed using coserp
Performed with t * t
Uses the famous 'smooth step' formula: t = tt * (3f - 2ft)
A play on the smooth step formula: t = ttt * (t * (6f*t - 15f) + 10f)