What the Flip is an Animation Network? - PART 2
Last week we gave an introduction to animation networks, what they are, where they came from and what they're used for. If you missed it or fancy a refresher, you can catch up here!
Last week we didn't really dig into how they're used, it was more of an overview, so this week we'll delve a little deeper. Again we'll be keeping it as a pretty simple overview, so it's accessible to all. Apologies in advance if you're expecting a super detailed technical breakdown!
So, by the end of last week we'd established that there was this big map of all of a characters animations. The game can pick and chose from this depending on the player input or scenario. This week we'll look at some of the other key elements of a character's animation network.
Current Location = Current Animation
Our current position or location within the animation network dictates what animation is playing at any one time, to play a different animation we have to move from our current animation state to a different position (and therefore animation) in the the network. When we create the network we can specify what our starting position in the animation network is. Usually this is the character's idle wait animation as it's the one we want to play when there is no player input at the start of a game or scene.
So our current position in the network picks what animation we're playing, but how do we move our position to a new animation state and play a new anim?
So the blocks in the network are the individual animations (or possibly groups of animations, we'll come to that later). The transitions are the lines in between the blocks. These transition lines essentially dictate which animations we can choose to move to from our current position, if there is not transition line connecting nodes then we cannot go there.
Think of these transitions as a cross-fade between records; we fade one animation down as we fade the other animation up, blending between them.
Default Blend/Into and Out anims
Now sometimes a default transition may look a little weird. There is nothing intelligent about it, it's literally blending from one animation to the next. It has no insight into how the human body works or what looks realistic. Usually if the animations we are blending to/from are similar it looks fine, but if the difference between the anims we're blending is considerable, then the default transition may look weird. To solve this we can add 'Into' and 'Out' animations. There are essential bridge animations we author to have more control over the transition and make sure it blends in a believable way.
As we have complete control over the animation network we can simply plug these new states in and change the path from one animation node to the next. Simple!
Each transition line has properties that we can set to dictate the specifics of how the transition from one animation to another works. For example, you can say whether the transition should trigger immediately, breaking out of the current animation, or wait until the current one has finished.
You can also set the duration of the blend - is it quick or slow?
You might notice that sometimes there are multiple transition lines leaving a single node, meaning that we have multiple animation options to choose from. How does the game pick which transition path to take? Well, a key part of transitions are conditions and animation variables.
So how do we pick? One of the key properties a transition can have is a condition, only if the condition is true will the transition path be taken! So what are we testing for in these conditions? We're testing for animation parameters.
These are simple booleans variables(although you can use different parameter types), essentially an 'on' or 'off' switch, that we set in game that tells the animation network which transition paths to take and determine what animation we will play next. For example in game if we set the variable 'Skip_Trigger' to be true, the network knows to take the transition path to the 'Skip' animation.
Groups and the Noddle Monster
As you add animations to your game the network can quickly become messy and unreadable, a giant spaghetti junction of nonsense that will fry your brain when you return to look at it after a break. One good way of sorting this out is by encapsulating multiple animation states within groups (called sub-state machines in Unity).
By grouping animation states in this way you also cut down on the number of individual transitions. Rather than transitioning from one individual anim to another individual anim, we simply transition out of our current parent group. From this point we pick the next parent group to move to (in this instance 'Kinematic Anims') then once we hit that group we choose the specidic Kinematic Anim to play. The original animation we came from doesn't need to know the details of all the different Kinematic anims, it just needs to get to the parent animation group as instructed, then the network can pick for itself.
This makes adding new animations into the network much easier as there are less transitions to set up and less visual noise and noodle mess when trying to read it at a glance,...DOUBLE WIN.
So that's it for our two part look at character's animation networks, we might return to look at more specifics but hopefully that has given you a good peak behind the wizard's curtain.
Until next time,
Alex & Tom.