Skip to main content
Unity 3D Basics – Complete Beginner to Advanced Guide
CHAPTER 09 Beginner

Animations and Animator Controller

Updated: May 16, 2026
30 min read

# CHAPTER 9

Animations and Animator Controller

1. Introduction

A static 3D model sliding across the floor breaks immersion immediately. To bring a character to life, their legs must pump when they run, they must recoil when hit, and they must swing their sword when attacking. Unity provides a robust, visual node-based system to manage these complex movements called the Animator Controller. In this chapter, we will master the Unity Animation system. We will explore how to import animations, build a State Machine, set up conditional Transitions, and seamlessly blend walking and running loops using Blend Trees.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Understand the difference between an Animation Clip and an Animator Controller.
  • Build a visual State Machine in the Animator Window.
  • Create Transitions between animations using Parameters (Booleans, Triggers).
  • Trigger animations from C# scripts.
  • Use a Blend Tree to smoothly mix idle, walk, and run animations.

3. Clips vs. Controllers

  • Animation Clip (.anim): A single, specific movement. (e.g., "Jump", "Run", "Die"). Usually created in Blender/Maya and imported into Unity.
  • Animator Controller: The "Brain". A visual flowchart that tells Unity *when* to play which Animation Clip. (e.g., "If speed > 0, play Run. If speed == 0, play Idle").

4. The Animator Window (State Machine)

  1. 1. Select your 3D character (it must have an Animator component).
  1. 2. Go to Window -> Animation -> Animator.
  1. 3. This opens a node-graph window. You will see an "Entry" state.
  1. 4. Drag an Animation Clip (like "Idle") from your Project window into the Animator. It becomes a rectangular Node.
  1. 5. The default arrow from "Entry" connects to "Idle". When the game starts, the character will immediately breathe idly!

5. Animation Parameters and Transitions

How do we switch from Idle to Run?
  1. 1. In the Animator Window, look at the top left and click the Parameters tab.
  1. 2. Click the + button and add a Bool (True/False) named isRunning.
  1. 3. Right-click the "Idle" node -> Make Transition, and drag the arrow to the "Run" node.
  1. 4. Click the white transition arrow. In the Inspector, look at the "Conditions" list.
  1. 5. Add a condition: isRunning == true.
  1. 6. (Important): Uncheck Has Exit Time. If left checked, the character will refuse to run until the Idle animation finishes its current loop, causing the controls to feel unresponsive. Unchecking it forces an instant, smooth blend.

6. Controlling Animations via C#

To make the animation actually happen during gameplay, your movement script must talk to the Animator component and change that isRunning parameter!
csharp
1234567891011121314151617181920212223242526
using UnityEngine;

public class PlayerAnim : MonoBehaviour
{
    public Animator anim; // Drag the Animator component here

    void Update()
    {
        // If player is pressing W, A, S, or D
        if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0)
        {
            // Set the Animator parameter to true!
            anim.SetBool("isRunning", true);
        }
        else
        {
            anim.SetBool("isRunning", false);
        }

        // Trigger a one-off animation like a jump or attack
        if (Input.GetKeyDown(KeyCode.Space))
        {
            anim.SetTrigger("JumpTrigger");
        }
    }
}

7. Blend Trees (Advanced Smoothness)

If your game supports analog controllers, the player might push the stick halfway. They shouldn't play the full "Sprint" animation, they should play a "Jog".
  • A Blend Tree takes a Speed float parameter (0.0 to 1.0).
  • If speed is 0.0, it plays Idle.
  • If speed is 0.5, it mathematically blends 50% Idle and 50% Run, resulting in a smooth Jog!
  • If speed is 1.0, it plays full Run.
Blend trees are the industry standard for polished AAA movement.

8. Visual Learning: The Animator Flowchart

txt
123456789101112
[ PARAMETERS ]
bool isRunning
trigger isDead

          [ Entry ]
              |
              v
[ Idle ] <--------> [ Run ]
  |  (isRunning=true)
  |  (isRunning=false)
  |
  +-- (isDead triggered) --> [ Death_Animation ]

9. Best Practices

  • Mixamo: If you are a solo developer and cannot animate 3D characters yourself, use Adobe Mixamo (mixamo.com). It is a massive, free library of thousands of high-quality, motion-captured animations (running, shooting, dancing) that import perfectly into Unity.

10. Common Mistakes

  • Root Motion Chaos: Have you ever triggered a walking animation, and the character visually walks forward, but when the animation ends, they snap instantly back to where they started? This is a "Root Motion" issue. By default, animations should move in-place, and your C# Rigidbody code moves the physical capsule. Ensure "Apply Root Motion" is unchecked on the Animator component unless you specifically want the animation file to drive the physical transform.

11. Mini Project: Setup an Idle-Run State Machine

Objective: Create a character that idles and runs based on key presses.
  1. 1. Download a free character with Idle and Run animations from the Unity Asset Store.
  1. 2. Drag the character into the scene. Make sure it has an Animator component.
  1. 3. Right-click in the Project window -> Create -> Animator Controller. Name it "PlayerAnim".
  1. 4. Drag "PlayerAnim" into the Controller slot on the character's Animator component.
  1. 5. Open the Animator window. Drag the Idle and Run animation clips into the window.
  1. 6. Create a Bool parameter named isMoving.
  1. 7. Make a transition from Idle to Run (Condition: isMoving = true, Has Exit Time: False).
  1. 8. Make a transition from Run back to Idle (Condition: isMoving = false, Has Exit Time: False).
  1. 9. Write a small C# script to set the bool to true when Input.GetKey(KeyCode.W) is pressed. Watch your character come to life!

12. Practice Exercises

  1. 1. What is the difference between an Animation Clip and an Animator Controller?
  1. 2. If you want a punch animation to interrupt an idle animation instantly, which checkbox on the Transition Arrow must you disable?

13. MCQs with Answers

Question 1

You want an animation (like a Death sequence or a Sword Swing) to play exactly once and then stop, rather than being toggled on and off. Which Animator Parameter type should you use?

Question 2

What advanced Animator feature allows you to perfectly, mathematically blend a slow-walk animation with a fast-run animation based on how far the player is pushing an analog thumbstick?

14. Interview Questions

  • Q: Explain the architecture of the Unity Animator Controller. How do States, Transitions, and Parameters interact to form a State Machine?
  • Q: A character's jump animation feels sluggish and unresponsive to the player's input, waiting a half-second before actually playing. What specific Transition setting is causing this, and why?
  • Q: Contrast "In-Place" animation combined with Rigidbody movement versus "Root Motion" animation. When would a developer intentionally use Root Motion?

15. FAQs

Q: Can I trigger a C# script FROM an animation? A: Yes! This is called an Animation Event. You can open the Animation timeline, place a marker exactly on the frame where the sword hits the ground, and tell Unity to run a C# function called PlayClankSound() on that exact frame.

16. Summary

In Chapter 9, we brought motion to our models. We learned that the Animator Controller acts as the brain, using a visual state machine to switch between Animation Clips. We created Transitions governed by Parameters (Bools and Triggers) to move from an Idle state to a Running state. We learned the golden rule of unchecking "Has Exit Time" for responsive controls, and wrote the C# logic required to bridge our input system to our visual animations.

17. Next Chapter Recommendation

Our game looks great, but it's completely silent. Time to add an atmosphere. Proceed to Chapter 10: Audio and Sound Effects.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·