Working with Animations

Unity has two animation systems, both supported by Atavism. That said, the new animation system Unity has created provides much better support and is easier to use with Atavism. *Note: Currently the default demo characters still use the legacy animation system and the UMA demo uses the new animation system. The default demo will be updated at some point in the near future to use the new system.*

Regardless of the animation system used, player/mob (from here on referred to as only mobs) animations are controlled by the MobController script that should be on every character and mob prefab.

### Animation categories

Animations come in two categories, general and override. General animations are looping animations such as idle, walk or run that are determined by the state of the mob. Override animations are one-off animations such as a wave or sword swing that override the general animations.

#### How General Animations are Managed

General animations are played whenever there is no override animation active. The Mob Controller reads in the Movement State of the mob (Running, Swimming or Flying), the current movement or velocity of the mob and a few other states (dead or alive? in combat?) to determine what animation should be played.

#### How Override Animations are Managed

An override animation is set when the PlayAnimation() function is called with both an animation name and length to play it specified. The Mob Controller then plays that animation until either the time expires or a new override animation is set.

### Using the Unity Animator

The Unity Animator has a state/transition system to work out which animation should be played based on various properties. It is recommended you take some time to familiarise yourself with the system by reading this: https://docs.unity3d.com/Documentation/Manual/Animator.html. *Note: the prefab needs the Animator component on it to use the new Animator system.*

The Mob Controller provided with Atavism sets the parameters for the Animator (see section above for how what animation to play is worked out) and then the Animator determines which animation to play. The result is most of your animation setup will be using the Animator tool, you should not need to make many (or any) changes to the Mob Controller. The Animator setup provided with the demos are ready to work with the general animations, but will require you to handle override animations as these will be specific to your game.

How it works is, the name of the Animation you set in the PlayAnimation() function for the mob controller is the name of the parameter that will be set in the Animator tool. So if you tell the mob controller to play “Bow” you need a “Bow” parameter set in the Animator tool, which the MobController will set to true, then set to false when the length of time has passed. Example steps for a Point animation:

1. You create a Bool Parameter in the Animator tool called Point.
2. You create a new state in the Animator tool, name it Point and set the Motion to some animation (ideally one that points…)
3. You create a new transition from the Idle State to your new Point State with the condition Point is True, and then a transition back for when Point is false.
4. In one of your scripts you call PlayAnimation(“Point”, 2);

Now when that script is run, the “Point” property on the Animator tool will be set to true, then back to false 2 seconds later. This will cause the Animator to change state from Idle to Point, thus playing the Point animation, then returning back to the Idle state in 2 seconds time.

### Using the Legacy Unity Animation System

The Legacy Unity Animation system is a lot more limited as it requires each animation to be dragged into the MobController. This means if you want more than the default animation options you need to edit the code in the MobController to handle it which can be a bit tricky. By default, the legacy animation system handles the idle, walk, run, jump, combat idle, unarmed attack and death. You can make these work by dragging in the animation object into the animation slot on the mob controller component on the mob prefab.

*Note: the mob prefab needs the Animation component on it to use the legacy animation system.*