Character Animation
Animating a character requires seamlesslly blending between different animation based on what the character is doing. The CharacterAnimationComponent
makes this easy allowing you to declaratively define how to transition between animation clips using state machines.
Playing a single animation
First, we will use the character animation component to simply play a single animation similarly to the example in the Animation system article.
Using animation state machines
To visualize what the character is doing we likely want to play different clips. This is easily done with an animation state machine which can transition between different animation clips based on state and defined transition rules.
The example below is a bit more involved to better illustrate how animation state machines can be used.
First, we load the model and extract the animation clips we intend to use.
Then we set up the character animation component with the mesh we intend to animate.
To play different animation based on state changes, we set up some way for the player to provide input. We use an
ActionInput
to represent the state of the player wanting to walk. After that we configure the input service. You can read more about how this works in Player input. Note that this code may ideally belong somewhere outside the character actor so that the character actor also can be used without being affected by the player's input.Create animation states for each clip. These allow us to build up the state machine for how to transition between them.
We use the transitionsBetween method with a predicate to transition to the walk state when walk input is activated. If the provided function later returns false, such as when the player no longer presses walk, the animation will return back to the idle animation.
Create an animation state machine and pass in the initial state.
Finally, instruct the character animation component to play the state machine.
In the next article, we will explain animation state machines more in depth and how they can be used to represent various transitions.
Last updated