Game Development

Unity Animator Setup for 2D Character Movement and Animation Transitions

Set up a Unity Animator for a 2D player with idle and run states, a Bool parameter, and instant transitions that respond to movement input.

7 min read
Unity editor with a pixel character visible in the scene view and the animation timeline open at the bottom.
Unity shows a pixel character in the scene view with the Animator animation timeline open below. — footage: Wild Cockatiel Games

Set up a Unity Animator for a 2D player by making an Animator Controller with idle and run animation clips, ensuring idle is the default state, and adding a Bool parameter that scripts set when the player moves, switching the animation immediately by setting the transition duration to zero so there’s no delay.

What to set up before you wire movement into the Animator

prerequisites

  • Create an Animations folder in your Assets to store the controller and animation clips.
  • Make a new Animator Controller in the Animations folder for your player.
  • Create an idle animation clip and a run animation clip, and check Loop Time for both so they repeat.
  • Add an Animator component to your player GameObject and assign the controller to its Controller field in the Inspector.

Unity editor with the Project window open to Assets/Animations, the Animations folder selected in the folder tree and the empty folder contents shown.

The Unity Project window is open to the Animations folder under Assets, with the folder selected and empty. — Wild Cockatiel Games

Unity Editor with the Player object selected in the Hierarchy and the Animator component expanded in the Inspector showing a controller assigned.

The Player object is selected and its Animator component shows an assigned controller in the Inspector. — Wild Cockatiel Games

Build the state machine for idle and run

steps

  1. Open the Animator window by selecting Window, then Animation, then Animator.
  2. Drag the idle animation clip into the Animator. The state turns orange, marking it as the default starting state.
  3. Drag the run animation clip into the Animator so both idle and run states appear, but do not connect them yet.

Unity Editor with the Animator tab open, showing Any State and Entry in the state machine graph and Idle and Run animation assets in the Project panel.

The Animator window is open with the controller graph visible and Idle and Run animation assets ready in the Project panel. — Wild Cockatiel Games

Add the movement parameter that controls animation transitions

steps

  1. In the Animator, open the Parameters tab and add a parameter of type Bool, name it is running.
  2. Right-click the idle state and select Make Transition, then click on the run state to create a transition arrow.
  3. Select the transition arrow and set the condition to is running is true. This switches to run when the parameter is set by your script.
  4. Create a return transition by right-clicking the run state, making a transition back to idle, and set its condition to is running is false.
  5. Ensure the parameter name is spelled exactly the same in the Animator and in your movement script.

Unity Animator window with the Parameters tab open and the add parameter menu showing Float, Int, Bool, and Trigger options, with Bool highlighted.

The Animator window shows the Parameters area with the add menu open and Bool selected. — Wild Cockatiel Games

Hook the player movement script to the Animator

steps

  1. Add a serialized private Animator field in your player movement script to link the Animator:
    using UnityEngine;
    
    public class PlayerMovement : MonoBehaviour
    {
        [SerializeField] private Animator animator;
    
        private float input; // Replace with your own input logic
    
        void Update()
        {
            // Replace with your own input check, e.g.:
            input = Input.GetAxisRaw("Horizontal");
    
            if (input != 0)
            {
                animator.SetBool("is running", true);
            }
            else
            {
                animator.SetBool("is running", false);
            }
        }
    }
  2. Assign the Animator component from your player GameObject to the script’s field in the Inspector.
  3. Set the Bool to true when there is movement input, and set it to false when the input returns to zero.

Fix the delay in the animation transition

Unity Editor showing the Animator graph with an Idle to Run transition selected and its settings open in the Inspector.

Unity Editor displays the Animator transition from Idle to Run with its settings visible in the Inspector. — Wild Cockatiel Games

Sprite animation setup for beginners

Unity Editor with the Animation window open at the bottom showing a sprite clip timeline with multiple keyframes, while a small character sprite is visible in the Scene view.

The Unity Animation window shows a sprite clip timeline with keyframes spread across the track. — Wild Cockatiel Games

  • Open the Animation tab for your player object to edit and preview clips.
  • Drag a sequence of sprite frames into the animation timeline to build idle or run clips.
  • Stretch the timeline if the animation plays too quickly.
  • Enter Play mode to confirm the player visually animates in the Scene before you wire up transitions.

Unity Animator parameters for movement

  • Use a Bool for switching between idle and movement in a simple state machine.
  • Double-check that the parameter name matches exactly in both the Animator and your script.
  • If your player stays in run even when not moving, confirm the script sets the Bool back to false when input is zero.

Also worth knowing

  • Transition delay fix: Setting Transition Duration to 0 removes the unwanted pause before the animation switches states.
  • Script–Animator match: The name used in SetBool and the Animator parameter must match exactly for transitions to work.
  • Idle/run logic: If your player keeps running while not moving, ensure the script sets the Bool back to false when there’s no input.
  • Movement direction flip: Flipping the player left/right for movement direction is usually handled in an earlier step, before setting up these animations.
  • Next steps: The typical next feature after idle/move animation is adding a jumping state, which builds on this setup.

FAQ

how to set up Unity Animator for 2D character movement

Create an Animator Controller with idle and run animation clips, set idle as the default state, add a Bool parameter named "is running," and set this parameter from your movement script depending on player input.

Unity 2D animation transitions tutorial

Set up transitions in the Animator from idle to run and back using a Bool parameter, ensuring transitions happen instantly by turning off Has Exit Time and setting Transition Duration to 0.

Unity blend tree for walking and idle

This setup is a simple two-state Animator using a Bool parameter to switch between idle and run. Blend Trees are not used here; for this pattern, use direct transitions with a Bool.

Unity sprite animation setup for beginners

Drag your sequence of sprites into the timeline in the Animation window to create an animation clip, check Loop Time for repeating animations, and preview in Play mode before connecting logic.

Unity animator parameters for movement

Use a Bool parameter named "is running" to signal when the player should switch between idle and run. Make sure the name in the parameter and the code matches exactly, and update it based on player input.


Official reference: Unity manual.

Sources

Screenshots on this page are frames from the videos below, used to illustrate the steps they describe. All rights remain with their creators.

Checked against: