Course contentsShow
← Unity Game Development
Lesson 371 of 8286. Animation and CinemachineFree lesson

Creating One-Dimensional Blend Trees

You will blend multiple animations based on a single float parameter to create smooth transitions for movement speeds.

Creating One-Dimensional Blend Trees

In this lesson, you will learn how to use a one-dimensional Blend Tree to create smooth, fluid transitions between animations based on a single movement speed value.

The Problem with Basic Transitions

In a standard state machine, you might use discrete states like "Idle," "Walk," and "Run." However, triggering these states abruptly creates "snapping," where the animation jumps instantly from one pose to another. If your character’s movement speed changes dynamically, you want the animation to look like it is physically accelerating or decelerating in real-time.

How a Blend Tree Works

A Blend Tree is a special state within your Animator Controller that acts as a container for multiple animations. Instead of manually drawing transitions between individual states, you add your clips into the Blend Tree and map them to a single float parameter (e.g., Speed).

  1. Open the Animator Window: Right-click in the grid, select Create State > From New Blend Tree.
  2. Configure the Parameter: Double-click the Blend Tree to enter it. In the Inspector, ensure the "Parameter" is set to your float variable (like Speed).
  3. Add Motion Fields: Click the "+" icon to add your clips—Idle (at 0), Walk (at 1), and Run (at 2).

Unity calculates a "weighted average" between these animations. If your Speed parameter is set to 1.5, Unity will automatically blend the Walk and Run animations proportionally, resulting in a smooth "jog" animation that sits perfectly between the two clips.

Scripting the Blend

To make this work in-game, you simply update the float parameter via script based on your character's velocity:

void Update()
{
    float currentSpeed = GetComponent<Rigidbody>().velocity.magnitude;
    animator.SetFloat("Speed", currentSpeed);
}

By passing your speed value directly into the Animator, the Blend Tree takes over, seamlessly mixing the animations so the character’s legs appear to speed up or slow down exactly as the game object moves through the world.

Key Takeaway: A one-dimensional Blend Tree eliminates animation snapping by using a single float parameter to interpolate between multiple clips, creating a seamless visual response to changing movement speeds.