Easing.md
May 23, 2024 · View on GitHub
Easing
The Motion objects animate properties between an initialValue and a finalValue for the specified duration. By default the animation will happen with constant speed, which in other words, uses a linear function to interpolate between the two values:
But the Motion objects receive an easing paramater that is a function which will accelerate/decelerate the animations in different ways.
A good place to visualize easing functions is Robert Penner's website
C#
In the code below, the easing function is MotionKitEasing.BackOut that correspond to one the built-in functions:
MotionKit.GetMotion(m_Ball, "Position", p => m_Ball.localPosition = p)
.Play(new Vector3(0, 0, 0), new Vector3(3, 0, 0), 2)
.SetEasing(MotionKitEasing.BackOut);
By using different functions, the animations will look more interesting and will likely have more artistic value.
The class MotionKitEasing has many built-in functions that you can visualize in the Robert Penner's website, but there are also some other options:
MotionKitCurve(AnimationCurve): Uses a UnityAnimationCurvethat you can customize in the inspector.Blink: Changes between the initial and final value repeatedly like blinking. For example, black, white, black, white, etc.Pulse: Increments a value like in a Bell Curve. Why didn't I named it "Bell Curve"? Only God knows why...Shake: Makes things shake as you would expect in video games. This is good for a camera shake, for example.
This special functions are called ParameterizedEasing and more documentation on this will come later.
Inspector
In the MotionKitComponent you just choose from a list of easing functions:
And if you choose from some of the ParameterizedEasing functions (AnimationCurve, Blink, Pulse or Shake), additional parameters will appear on the inspector: