A Blend Tree is a feature within Unity’s Animator Controller that allows you to smoothly transition between multiple animations based on one or more parameters (like speed, direction, or vertical velocity). It’s ideal for creating fluid and natural character movement.
🎯 Common Use Cases
Scenario | Description |
---|---|
Walk/Run Transition | Blend idle, walk, and run animations based on speed . |
Jump & Fall Animation | Use velocityY to blend between jump, mid-air, and fall states. |
Directional Movement | Blend 2D directional inputs (Horizontal , Vertical ) for 8-way movement. |
Action Intensity | Vary animation strength (e.g. light, medium, heavy attacks). |
🧱 Blend Tree Types
✅ 1D Blend Tree
- Uses a single parameter (e.g.,
speed
,velocityY
). - Best for linear transitions like walk → run or jump → fall.
✅ 2D Blend Tree
- Uses two parameters (e.g.,
Horizontal
,Vertical
). - Ideal for directional movement (e.g., top-down 8-direction walk).
Types:
- 2D Simple Directional – Basic directions
- 2D Freeform Directional – Smooth, angle-based blending
- 2D Cartesian – Blending based on X/Y grid values
⚙️ How to Create a Blend Tree
- Open your Animator Controller.
- Right-click → Create State → From New Blend Tree.
- Double-click the Blend Tree to configure it.
- Set the Blend Type (1D or 2D).
- Assign the Blend Parameter (e.g.,
velocityY
). - Add animation clips and define their thresholds.
- Add transitions into/out of the Blend Tree (e.g.,
isGrounded == false
).
🧪 Example: 1D Jump/Fall Blend Tree
Continue with previous demo, let’s add Jump and Fall animation with Blend Tree:


private void AnimatePlayer()
{
// Animate player running
bool isRun = rb.velocity.x != 0;
// New Added code to set yVelocity parameter
playerAnim.SetFloat("yVelocity", rb.velocity.y);
playerAnim.SetBool("isRun", isRun);
playerAnim.SetBool("isGrounded", isGrounded);
}
Full Code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerScript : MonoBehaviour
{
private Rigidbody2D rb;
private Animator playerAnim;
[SerializeField] private float moveSpeed = 5;
[SerializeField] private float jumpForce = 10;
private float xInput;
private int facingDirection = 1;
private bool facingRight = true;
[Header("Collision Info")]
[SerializeField] private LayerMask groundLayer;
[SerializeField] private float groundCheckDistance;
private bool isGrounded;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
playerAnim = GetComponentInChildren<Animator>();
}
// Update is called once per frame
void Update()
{
CheckInput();
CollisionChecks();
Movement();
// Flip the player based on input direction
FlipController();
AnimatePlayer();
}
private void CollisionChecks()
{
isGrounded = Physics2D.Raycast(transform.position, Vector2.down, groundCheckDistance, groundLayer);
}
private void CheckInput()
{
// Get horizontal input
xInput = Input.GetAxis("Horizontal");
// Jump on Space key press
if (Input.GetKeyDown(KeyCode.Space))
{
Jump();
}
}
private void Movement()
{
// Apply horizontal movement
rb.velocity = new Vector2(xInput * moveSpeed, rb.velocity.y);
}
private void Jump()
{
if (isGrounded)
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
}
private void AnimatePlayer()
{
// Animate player running
bool isRun = rb.velocity.x != 0;
playerAnim.SetFloat("yVelocity", rb.velocity.y);
playerAnim.SetBool("isRun", isRun);
playerAnim.SetBool("isGrounded", isGrounded);
}
private void Flip()
{
facingDirection = facingDirection * -1;
facingRight = !facingRight;
transform.Rotate(0, 180, 0);
}
private void FlipController()
{
if (rb.velocity.x > 0 && !facingRight)
{
Flip();
}
else if (rb.velocity.x < 0 && facingRight)
{
Flip();
}
}
private void OnDrawGizmos()
{
Gizmos.DrawLine(transform.position, new Vector3(transform.position.x, transform.position.y - groundCheckDistance));
}
}
✅ Benefits
- Smooth transitions without manually configuring multiple state links.
- Scalable structure—easy to extend with more motions or complexity.
- Cleaner logic—ideal for continuous actions like speed, jump height, or direction.