New Animation 2D and 3D GameActions

Wave Engine 2.3.0 (Saw Shark) has added a lot of new features. One of them is a new set of GameActions specialized for animating entities. In this article you may have been realized that GameActions are a really powerful and customizable way to create your own behaviors and interact with others in an easy flow, creating sequential and parallel GameActions to animate your entities. However, they relied on the user the task of creating its own animations as WaveEngine offered the architecture.

Good news is that we’ve included a complete set of GameActions in WaveEngine.Components package. That includes type animations for simple types and transform animations for rotating, scaling and translating entities.

And because they are GameActions, they can be played in sequential order or parallel to others.

Base Type Animations

These animations are the base of the more complex transform animations. This type game actions are used for animating different WaveEngine types (float, Vector2, Vector3 and Quaternion). All of them are similar, they consist in setting an initial and ending value, and passing it an update method that will receive an updated value to work with.

FloatAnimationGameAction

This GameAction is used for animating a float value. In the next code you can see its constructor:

  • entity:  The entity that will be affected by the game action.
  • from: Init value.
  • to: Value at the end.
  • time: time of the animation.
  • ease: Enum of the different easing functions for the game action.
  • updateAction: Update action method that will be called every step of the animation and will have a float as a parameter.

For the developer, the updateAction is the key element for animating the entity, because it’s the piece of code that transforms the float value into a behavior.

For example, if we want to make a smooth zoom of a camera3D we only have to animate its FieldOfView property:

var camera3D = cameraEntity.FindComponent<Camera3D>();
var anim = new FloatAnimationGameAction(cameraEntity, 
                                        0.79f, 
                                        0.2f,
                                        TimeSpan.FromSeconds(10), 
                                        EaseFunction.CubicInOutEase,
                                        (f) =>;
                                        {
                                          camera3D.FieldOfView = f;
                                        });
anim.Run();

Vector2AnimationGameAction

This GameAction works in the same way as the previous one but with Vector2. The updateAction method will receive a Vector2 parameter so you can use to animate as you wish. If you are thinking of using this GameAction for translating 2d entities, you may keep reading and take a look at the TransformAnimations.

Vector3AnimationGameAction

This GameAction works in the same way as the previous ones but with Vector3. The updateAction method will receive a Vector3 parameter so you can use to animate as you wish. If you are thinking of using this GameAction for transforming entities (translating, rotating, scaling), you may keep reading and take a look at the TransformAnimations.

QuaternionAnimationGameAction

This GameAction works in the same way as the previous one but with Quaternion. The updateAction method will receive a Quaternion parameter so you can use to animate as you wish. If you are thinking of using this GameAction for rotating entities, you may keep reading and take a look at the TransformAnimations.

Transform Animations

On top of the Base Type Animations, we’ve added a set of Transform animations, useful for rotating, translating and scaling your 2D and 3D entities. They inherit the Type Animations, and we’ve added them just for simplification, being really useful for creating simple entity animations.

MoveTo2DGameAction

This GameAction translates the Transform2D component of an entity to a specified position during a specified time.

  • entity: The animating entity.
  • to: the final position.
  • time: Duration of the animation.
  • ease: Easing function of the animation. Useful for smooth behaviors (None by default)
  • local: If the animation uses local coordinates. (False by default)

MoveTo3DGameAction

This GameAction translates the Transform3D component of an entity to a specified position during a specified time.

  • entity: The animating entity.
  • to: the final position.
  • time: Duration of the animation.
  • ease: Easing function of the animation. Useful for smooth behaviors (None by default)
  • local: If the animation uses local coordinates. (False by default)

RotateTo2DGameAction

This GameAction rotates the Transform2D component of an entity to a specified angle during a specified time.

  • entity: The animating entity.
  • to: the final angle.
  • time: Duration of the animation.
  • ease: Easing function of the animation. Useful for smooth behaviors (None by default)
  • local: If the animation uses local coordinates. (False by default)

RotateTo3DGameAction

This GameAction rotates the Transform3D component of an entity to a specified rotation during a specified time.

  • entity: The animating entity.
  • to: the final rotation.
  • time: Duration of the animation.
  • ease: Easing function of the animation. Useful for smooth behaviors (None by default)
  • local: If the animation uses local coordinates. (False by default)

ScaleTo2DGameAction

This GameAction scaled the Transform2D component of an entity to a specified scale during a specified time.

  • entity: The animating entity.
  • to: the final scale.
  • time: Duration of the animation.
  • ease: Easing function of the animation. Useful for smooth behaviors (None by default)
  • local: If the animation uses local coordinates. (False by default)

ScaleTo3DGameAction

This GameAction scales the Transform3D component of an entity to a specified scale during a specified time.

  • entity: The animating entity.
  • to: the final scale.
  • time: Duration of the animation.
  • ease (None by default): The easing function of the animation. Useful for smooth behaviors.
  • local (False by default): If the animation uses local coordinates.

Easing Functions

All the previous animations can be used with a predefined set of easing functions, passed as an enum parameter in the constructor. In the next diagram, you can learn the different easing functions and their interpolation curves. Chose the one who suits you.

Sample

In the GameActions article, we explained how to create a robot animation. Now we will recreate the same animation with these Transform Animations.

We have a robotic arm model, with the next hierarchy of entities:

In our animation, we will:

  1. Rotate zone0 180 degrees.
  2. Rotate zone1, zone2 and zone3  to reach cube1.
  3. Set visibility of cube1 to false and cube2 to true.
  4. Rotate zone0, zone1, zone2, zone3 to its initial values.

The next code creates the previous animation and plays it:

// Gets the objects
 var cube1 = this.EntityManager.Find("cube1");
 var cube2 = this.EntityManager.Find("base.zone0.zone1.zone2.zone3.cube2");
 var zone0 = this.EntityManager.Find("base.zone0");
 var zone1 = this.EntityManager.Find("base.zone0.zone1");
 var zone2 = this.EntityManager.Find("base.zone0.zone1.zone2");
 var zone3 = this.EntityManager.Find("base.zone0.zone1.zone2.zone3");
 var ease = EaseFunction.QuadraticInOutEase;
 var time = TimeSpan.FromSeconds(1.5);

 // Play the animation
 var animationSequence = new RotateTo3DGameAction(zone0, new Vector3(0, -MathHelper.Pi, 0), time, ease, true)
 .CreateParallelGameActions(new List<IGameAction>() { new RotateTo3DGameAction(zone2, new Vector3(0, 0, 0.087f), time, ease, true),
 new RotateTo3DGameAction(zone1, new Vector3(0, 0, 0.17f), time, ease, true),
 new RotateTo3DGameAction(zone3, new Vector3(0, 0, -0.45f), time, ease, true)
 }).WaitAll()
 .ContinueWithAction(() =>
 {
 cube1.IsVisible = false;
 cube2.IsVisible = true;
 })
 .CreateParallelGameActions(new List<IGameAction>() { new RotateTo3DGameAction(zone0, new Vector3(0, 0.64f, 0), time, ease, true),
 new RotateTo3DGameAction(zone1, new Vector3(0, 0, -1.2f), time, ease, true),
 new RotateTo3DGameAction(zone2, new Vector3(0, 0, 0.9f), time, ease, true),
 new RotateTo3DGameAction(zone3, new Vector3(0, 0, -1.2f), time, ease, true)
 }).WaitAll();

 animationSequence.Run();

The game will look like this:

SingleAnimations Deprecated

We can say that these GameActions are the successors of the previous animation system. That’s why we encourage you to start using these classes and stop using the classes AnimationUI, AnimationBase and SingleAnimation.

 

Leave a Reply

Your email address will not be published. Required fields are marked *