Table of Contents

Wave

The Wave class significantly streamlines the process of creating periodic animations.

Defining a wave

Waves are defined by, and created using, eight different parameters, which are as follows:

  • Upward Curve: Defines the "shape" of the half of the curve that moves up
  • Downward Curve: Defines the "shape" of the half of the curve that moves down
  • Up Period: Defines the amount of time it takes to travel the upward curve
  • Down Period: Defines the amount of time it takes to travel the downward curve
  • Amplitude: Defines the maximum value the wave reaches; this is 1 by default
  • Crest Wait: Defines the amount of time the wave maintains its peak
  • Trough Wait: Defines the amount of time the wave maintains its minimum
  • Uniformity: Defines how much the offset passed in when evaluating the wave is considered

The following diagram illustrates the first five parameters. On the left you see the upward curve, on the right the downward curve.

first wave diagram

The second diagram illustrates crest and trough wait.
Both essentially insert a period of time during which the wave's value does not change.

first wave diagram

The uniformity is hard to visualize in a diagram in this way; I find it easier to just imagine it abstractly as the uniformity the animation will show across the animated text segment. Below, you see the same animation with the exact same wave, except that the first animation uses uniformity = 0, the second uniformity = 0.25, the third uniformity = 1.

Creating a wave

You create a wave simply by passing in these eight values into Waves constructor.
Since this class is designed specifically to be used with animations though, likely you will mostly be creating it using the CreateWave method from the ParameterUtility class. For info about how to use wave as a parameter in your animations, see ParameterUtility Wave.

Evaluating a wave

Once you have created a Wave, you can evaluate it using a time value and an offset value: (float, int) Evaluate(float time, float offset).
As you can tell by the signature, Evaluate returns two values. The float is the actual value of the curve for the given time and offset. The integer indicates whether the curve is currently travelling up or down; if it is negative, the curve is moving down, if it is positive, the curve is moving up. This value is useful for when you want to switch the behavior of your animation depending on what curve the wave is currently travelling.
For example, the built-in fade animation can use different anchors depending on whether the character is fading in or out. The animation below visualizes how fade uses both values of the Evaluate method.

Checking wave extrema

You can check if the wave passed an extrema (so either the crest or the trough) during the last update, using the int PassedExtrema(float time, float deltaTime, float offset) method. Once again, you need the time value and the offset, and additionally here you need the deltaTime since you last checked. Essentially, the method checks whether the wave passed an extrema during the time interval of [timeValue - deltaTime, timeValue]. A positive return value indicates that a maximum was passed, a negative return value indicates that a minimum was passed, and 0 indicates neither was.

An additional, optional parameter is PulseExtrema. If the checked wave has a crest or trough wait, this parameter defines whether an extremum is passed once the wait time begins, or once it ends. PulseExtrema can also consider both to be an extrema, but of course be aware that it will then notify you of each extremum twice.

If multiple extrema were passed during the specified interval, it will notify you of the latest one.