- Copy the
PAnim.cs
class into your Unity3d project - You're done!
Animate objects by doing StartCoroutine(PAnim.Animation(...));
- The duration specifies how long the animation will run for
- The timing function maps the clock time into a parameter to be used for animation. The simplest, PAnim.Linear will produce a linearly varying parameter in the [0, 1] range. PAnim.EaseInOut will produce a value that accelerates from zero, then decelerates again on [0, 1]. There are more timing functions (but not many yet) and you can also write your own. (See below in "writing timing functions")
- The animation block does the work of animation. It takes one parameter, a float which will be (if your timing function is well behaved,) zero at the beginning of the animation and one at the end of the animation. Most tasks in the animation block should be performed by setting a value to the result of an interpolation. (If you want interpolations that behave well outside the [0, 1] range, look at Extrap.cs)
- The completion block will be called when the animation finishes
An animation block should usually simply interpolate between values, for instance
transform.position = Extrap.Lerp(Vector3.zero, Vector3.up, t);
will make the object move from the origin to one square above the origin following the curve defined by the parameter
A timing function controls the character of the animation. A well behaved timing function should:
- return 0 at the beginning for the animation
- return 1 at the end of the animation Your timing function takes one float representing the progress of the animation, and should return a float representing the distance the animation has moved. (How far an object is along it's path, how much the rotation has progressed, etc.)