This implementation provides a simple set of easing functions for various speed modifications in Unity. Easing functions are commonly used in animations to create smooth transitions and control the rate of change over time, allowing for effects like acceleration, deceleration, and oscillation. These native C# implementations are adapted from examples available on Easings.net, a popular resource for visualizing and understanding easing curves. The functions are designed to work seamlessly with Unity’s animation and movement systems, giving developers the ability to easily apply different types of motion, such as linear, quadratic, cubic, and elastic, to their game objects or UI elements. These easing functions are ideal for fine-tuning animations, transitions, and movement behaviors in games or interactive applications.
- InExpo
- OutExpo
- InOutExpo
- InBack
- OutBack
- InOutBack
- InSine
- OutSine
- InOutSine
- InCubic
- OutCubic
- InOutCubic
- InQuint
- OutQuint
- InOutQuint
- InCirc
- OutCirc
- InOutCirc
- InElastic
- OutElastic
- InOutElastic
- InQuad
- OutQuad
- InOutQuad
- InQuart
- OutQuart
- InOutQuart
Instead of the direct value of t / time, we may use the output of the Calc function to simulate a more organic acceleration. In the example we used the OutBack acceleration function.
[SerializeField] private EaseCurve curve = new EaseCurve(Ease.Type.OutBack);
private IEnumerator ScaleTween(Vector2 from, Vector2 to, float time)
{
float t = 0.0f;
while (t < time)
{
t += Time.deltaTime;
transform.localScale = Vector2.LerpUnclamped(from, to, curve.Calc(t / time));
yield return null;
}
transform.localScale = to;
}Note
Some curves like OutBack may overshoot the the range of [0.0, 1.0]. In these cases you should use LerpUnclamped instead of Lerp.