Home

Awesome

Interpolations

Lightweight Unity library for smoothing movements and value progressions in code (dragging, easing, tweening).

https://twitter.com/stephbysteph/status/1125462189450465280

API is currently experimental and may change.

Current Features

Examples

Smoothing out sudden value changes

// (Within an update call, i.e. FixedUpdate)
mixer.volume = Volume;
                 |
                 v
mixer.volume = mixer.volume.DragOut(Volume, 30);

Adding easing to a lerp call

Vector3.Lerp(a, b, ratio);
                     |
                     v
Vector3.Lerp(a, b, I.Cubic.InOut(ratio));

Check this cheat sheet for the effect of the different equations.

Tweening a position, the abstracted way

Tweens.Run(new PositionTween(transform))
      .To(targetPosition)
      .Timing(0, 1, I.Circ.InOut);

or using a shortcut:

Tweens.RunPosition(transform)
      .To(targetPosition)
      .Timing(0, 1, I.Circ.InOut);

or having it update within FixedUpdate/LateUpdate instead of Update:

Tweens.Fixed.Run...
Tweens.Late.Run...

Tweening a position, the controlling way

Tween<Vector3> positionTween;
...
positionTween = new PositionTween(transform))
      .To(targetPosition)
      .Timing(0, 1, I.Circ.InOut)
      .Start();
...
// In Update, FixedUpdate, or etc
positionTween.Update(Time.timeDelta)

Custom tweening instances

Tweens.RunFloat
(
    () => mixer.GetFloat("sfxVol", out float vol) ? vol : 0,
    vol =>
    {
        mixer.SetFloat("sfxVol", vol);
        indicator.alpha = vol;
    }
)
.To(targetVolume)
.Timing(0, 1, I.Sine.Out);

Tweens.Run(new ColorTween(myScript.GetColor, myScript.SetColor))
      .To(Color.yellow)
      .Timing(0, 1, I.Cubic.InOut);

Features Roadmap

Possible features

Meta

Interpolations https://github.com/phest/interpolations

By Steph Thirion.

Easing equations by Robert Penner, optimized by Tween.js authors.

All code open source under MIT License. See LICENSE file.