- Home /
how to use time on lerp
hi everyone, iàm trying to undestand how to make my lerp start faster like an impulse, the slow it overtime, iàm using this now
float t = currentLerpTime / lerpTime;
t = Mathf.Sin(t * Mathf.PI * 0.5f);
but doesnàt work as expected.. what i missing?
thank's you in advance
I passed my finger over your first Iàm to remove the dust particle off the screen ¯_(ツ)_/¯
Answer by jenci1990 · Nov 28, 2018 at 03:01 PM
This is a sinusoidal easing timing, but there are some other useful easing math. Try these:
//Sinusoidal (same as yours)
t = Mathf.Sin(t * Mathf.PI / 2f);
//Quadratic
t = t * (2 - t);
//Cubic
t = t * t * t + 1;
//Exponential
t = t == 1f ? 1f : 1f - Mathf.Pow(2f, -10f * t);
//Circular
t = Mathf.Sqrt(1f - (--t * t));
If these one not working, you make a mistake elsewhere.
Thank’s you for your reply, so i should be on the right way, im doing PI * 0.5f, but in your example it is for 2, maybe i should increase it to make it as i want
Hello there,
This answer is definitely correct.
To add to this, I like to send people to this page when talking about lerps and curves. Hopefully it helps!
Cheers,
~LegendBacon
Answer by UnityCoach · Nov 28, 2018 at 07:09 PM
You may want to use an AnimationCurve.
[SerializeField] AnimationCurve timeWarpCurve;
float t = timeWarpCurve.Evaluate(Time.time);
t = Mathf.Sin(t * Mathf.PI * 0.5f);