I spent some time playing around with a holiday asset pack that I snagged on the Unity Asset Store and discovered that the Santa I had purchased came with a series of animations. I decided to give the Animator a try to figure out some of the basics.
Given that this particular asset came with animations, there really wasn’t too much that I had to do. The Santa prefab already had an animator associated with it, so when I added him to the scene, an ‘Animator’ tab appeared at the top next to the Scene and Game tabs.
Initially, Santa only had two state boxes: ‘metarig|Santa_Idle’ and ‘Any State’. These two boxes represent the two states that Santa had in the game, beginning with the idle state. Under the Santa prefab asset, there were a whole host of options that we could animate our Santa with.
I decided to go with the metarig|SnowballThrow, because who doesn’t love the idyllic pastime of getting large globs of slush thrown at their heads? In virtual reality, there is no physical snow so you get to have all the fun of a frozen projectile fight without the mess. Sweet!
Because experimentation is the most fun way to learn, I dragged the item for the snowball throwing animation onto the Animator, where it showed up with it’s own box. After that, it was simply a matter of figuring out how to draw a connection between the idle state and the animation state. The Animator, from what I can tell, is a tool that allows you to specify different states, or animations, that your in-game characters can have based on different conditions. For this demo, I didn’t do any state changes that were based on player action, but I’ll cover that in another post.
Once the state was added for throwing the snowball, all that was left was to connect the states.
- Right-Click the starting state; in this example, this is the idle state.
Choose ‘Make Transition’ from the drop down menu.
An arrow will appear from the idle box. Drag this to the next state; in this example, this is the snowball animation box.
To loop the animation and have it run continuously, repeat this going from the snowball state back to idle.
With those steps, you’ve successfully done a basic animation using Unity Animator! This can be done using the free version of Unity (no pro license required) and the Animator actually contains a lot more detailed state machines that I will hopefully be able to get to in the coming weeks. This example was incredibly basic when you look at the complexity that Unity supports with their animations, and you can develop really rich AI in your game using states that react based on character actions and proximity.
Want more information on the Animator? Check out Unity’s official tutorial video on YouTube here!