i’m trying to make an exponential ease out curve that will decelerate over time but start fast, and i need to clamp it on 0-1 range, anyone can help me to figure out how to make it?
this is what i have
_currentLerpTime += in_deltatime;
float t = _currentLerpTime / _totalRotationTime;
// disegna una curva chiusa
t = Mathf.Sin(t * Mathf.PI * 0.5f);
/// applica la rotazione all'oggetto
Quaternion newRot
= QuaternionExtension.Lerp(_startRotation,_requestedRotation,t,false);
Vector3 current = newRot.eulerAngles;
_currentAngle = current.x;
_myCharacter.transform.localRotation
= newRot;
Wow, great visual easing resources @tonemcbride ! Thanks!
Also, to the OP, check for tweening tools in the Unity Asset Store. A lot of them have built-in easing functions of varying complexity and configurability.
so… for my case b and c will be 0 and 1 because i’m looking to use it on a lerp as time right? where t will be deltatime, and d the duration of it i suppose…
If you want to call an ease like a lerp you’d do it like so (where t is between 0-1):
public static float EasedLerp(Ease ease, float from, float to, float t)
{
return ease(t, from, to - from, 1f);
}
Mind you this method is based on if the ease method follows this specific shape:
/// <summary>
/// Represents an eased interpolation w/ respect to time.
///
/// float t, float b, float c, float d
/// </summary>
/// <param name="current">how long into the ease are we</param>
/// <param name="initialValue">starting value if current were 0</param>
/// <param name="totalChange">total change in the value (not the end value, but the end - start)</param>
/// <param name="duration">the total amount of time (when current == duration, the returned value will == initial + totalChange)</param>
/// <returns></returns>
public delegate float Ease(float current, float initialValue, float totalChange, float duration);
Which it appears the one Sylon87 posted does.
The link to github I supplied above includes tons of easing methods, and in the description of it I tell you that you can see visual representations of them all by visiting msdn here:
You seem to be passing ‘_currentLerpTime’ as the last parameter to EasedLerp rather than passing the ‘t’ value you just created. Maybe that’s the issue?
You also pass ‘_totalRotationTime’ as the ‘to’ value. I think that should be ‘CURVE_START_VALUE+_totalRotationTime’. That wouldn’t matter though if CURVE_START_VALUE was 0.
_currentLerpTime += in_deltatime;
// 't' will go from 0 to 1 over a period of 4 seconds
float t = Mathf.Clamp( _currentLerpTime / 4.0f , 0.0f , 1.0f );
// Lerp between 0 and 1 using 't'
float time = EasedLerp(0.0f,1.0f,t);
That’s odd, I’m not sure what it could be. The above code should take 4 seconds to go from 0 to 1 if you want to try it out.
and following it i was able to create a smothstart and smothstop function… smothstart is working well, but smothstop is working exactly as smothstart… i’m confused…