Animation

Last modified by Maarten Struijk Wilbrink on 2021/11/25 15:00

Animation Basics

The basics of animating a character in Unity are quite easy to master. Check out this tutorial to get you started. Other tutorials can be found here, and here: animating a character for instance. 

You need the following:

  1. A humanoid ‘rigged’ character. This means that the character has a rig which roughly resembles a human skeleton. You can obtain many good characters from Mixamo to get you started. Beware that the Mixamo characters do not have Blendshapes (see below), and that they’re best used for quick prototyping. 
  2. An animation which has been created for a Humanoid rig. Again, Mixamo to the rescue
  3. An Animator Component on the character. 

Animations are stored as animation clips in the Project. You drag and drop them into the Animator Controller in the Animator window. Then, you can right click and create a transition from one animation to the other. 

Depending on the settings you selected, the character will first display the first animation, and once that is finished, move on to the next, etc. 

However, this is roughly where the easy part is done. The next sections are about more advanced options. 

Transitions vs BlendTrees

In the above section, going from one animation to another was done using Transitions. This is a very useful method, because this way you can relatively easily create various animation states. However, animations that are closely related (such as animations regarding a character’s movement) can be more easily represented using a Blendtree

Controlling animations via code

As an example, you want your character to move from it’s ‘Idle’ animation into a ‘Waving’ animation via code. 

  1. Make sure that your Animator Controller is set up so that the Idle animation loops. You can do this by creating a transition from the animation unto itself. For some finetuning, you can set the transition time and duration in the Inspector. Make sure that ‘Has Exit Time’ is set to false. 
  2. Put the second animation in the Animator Controller. Create a transition rule in the ‘Parameters’ tab (such as a ‘Trigger’) and give it a name (e.g. “startWaving”). Create a transition from the Idle animation to the Waving animation, and set this new parameter as it’s trigger. 
  3. Write the controlling code, and drag in the Animator you want to control in the Inspector to the public field:
    public Animator animator;

    private void Update()
    {
      if (Input.GetKeyDown(KeyCode.Space))
       {
          animator.SetTrigger("startWaving");
       }
    }

    This wait until you have pressed the Spacebar, and triggers the Waving animation to be played. 

Changing animations

Chances are, the animations you were able to download through the AssetStore do not exactly fit your needs. Large libraries can be got, but often need cleaning. You will need to change the animations to your specifications. This is a) very difficult, and b) a lot of fun. 

Normally, animations are created by dedicated animators. It takes years of practice to become good at this aspect. Whether you’re aiming for a realistic style, or a more cartoony look, you’ll have to deal with things like timing, weight, and readability. Be mindful of this when you decide to change your animations. 

Here’s an excellent book on the basics of animation. It was originally made for traditional 2D animators, but the concepts translate well to 3D. One major difference between the original style of animation creation and what we do inside of Unity is dealing with the ‘inbetweens’. We have to create far fewer poses, and can let the computer interpolate between ‘key poses’ much more easily than was possible back in the day. 

UMotion is an excellent tool for creating (Community Version), and editing (Pro version) animations. It is much easier to work with than the standard Unity animation window. Other features found in the Pro version are animation layers (useful for editing existing animations), IK control (see below), and the ability to export as .FBX (reducing file-size and clutter). 

IK & FK

Forward Kinematics (FK) is the process of rotating each joint to a specific point, and having the animation be a culmination of all rotations. This is for instance the way you will need to animate hands. 

With Inverse Kinematics (IK), you can simply put the end joint to the position where you want the limb to be, and have the computer calculate where all the other joints need to be. This is a much more time-efficient way of animating, possibly at the cost of some very fine-detailed control. An excellent asset to work with IK is FinalIK, another solid option is Unity’s own Animation Rigging package (see Brackey’s Tutorial for more info).

You can combine FK and IK to create the animation to your liking. 

Facial animation, emotions & speech

For facial animations such as for speech and emotions, see here

Tags:
   
solo
XWiki 14.10.13
contact@xwiki.com