# Animator

> Aego 0.12.5 · development; docs build `4a32b816933e02930662f6a443cb25abe6050d090c55e237cbff5c44ae9b25f8`. [Build manifest](/docs-build.json).

An [Animator](/ref/animation.Animator.md) plays the states of a controller, an `.aectrl` file: each state has a clip, and transitions switch between states when parameters change. Scripts set the parameters; the graph does the rest.

In Try it, use A/D to walk, Space to jump and J to trigger Hit. The script sets controller parameters and shows the current state.

    func FixedUpdate(dt float) {
      m := node.Get<Motion2D>()
      a := node.Get<Animator>()
      a.SetFloat("Speed", math.Abs(m.Velocity.X))
      a.SetBool("Grounded", m.Grounded)
      if input.Pressed("Attack") {
        a.SetTrigger("Attack")
      }
    }

| Method | |
|---|---|
| `SetBool`, `SetInt`, `SetFloat(name, value)` | set a parameter; transitions read it on the next fixed step |
| `SetTrigger(name)`, `ResetTrigger(name)` | a one-shot parameter: the transition that uses it, or the end of that step, clears it |
| `GetBool`, `GetInt`, `GetFloat(name)` | read a parameter |
| `Play(state)` | switch to a state on the next fixed step, without a blend |
| `CrossFade(state, seconds)` | blend into a state |
| `IsState(name) bool`, `StateName(index) string` | the state, or the name of a state index |

| Signal | |
|---|---|
| `StateEntered(state int)` | a transition into the state started |
| `StateExited(state int)` | the state stopped playing, at the end of the blend |
| `Event(id int, payload float)` | a state reached an event of its clip |

State, Time, Progress and Blending show the state during Play. Create → Gameplay → Platformer Character comes with an Animator on the built-in controller `engine/anim/platformer`: Idle, Run, Jump and Hit, with the parameters Speed, Grounded and Attack.

Set parameters in `FixedUpdate` when they come from the game state, as above: the graph runs on fixed steps, so it then sees the same values on every replay at any frame rate.

## Animator and Motion 2D together

The platformer example drives its player from one `FixedUpdate`: the controller moves, the animator shows it. Both read the same step, so a replay at any frame rate gives the same states and the same hits.

    func FixedUpdate(dt float) {
      m := node.Get<Motion2D>()
      m.Move(input.Axis("Move"))
      if input.Pressed("Jump") {
        m.Jump()
      }
      a := node.Get<Animator>()
      a.SetFloat("Speed", math.Abs(m.Velocity.X))
      a.SetBool("Grounded", m.Grounded)
      a.SetFloat("VerticalSpeed", m.Velocity.Y)
      if input.Pressed("Attack") {
        a.SetTrigger("Attack")
      }
    }

The values describe the previous step: scripts run before Motion 2D moves. Damage reaches the animator through a signal, `Health.Damaged` → `SetTrigger("Hurt")`, and an `any` transition with `interrupt=true` shows it even in the middle of a blend. The sprite's Flip X stays with the script: it follows the input, not a clip.

In `examples/topdown` the work is split the other way: a State Machine decides what an enemy does (Patrol, Chase, Dead) and its hooks only set Animator parameters (`Chasing`, `Die`); the clips decide how it looks.
