# Character motion

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

[Motion 2D](/ref/gameplay.Motion2D.md) moves a character with a kinematic [Rigid Body 2D](/ref/physics.Body2D.md). Each fixed step it casts the body's colliders along the move, slides along what it hits and moves the body to the result, so the character never sinks into walls and still pushes crates.

Try walking with A/D or the arrow keys and jumping with Space, W or Up; the lift, slope and walls use the real physics system.

    m := node.Get<Motion2D>()
    m.Move(input.Axis("Move"))
    if input.Pressed("Jump") {
        m.Jump()
    }
    if input.Released("Jump") {
        m.JumpReleased()
    }

`Move` stays until the next call; `Jump` is one request that the controller keeps for Jump Buffer seconds, so a jump pressed shortly before landing still happens.

| Mode | Behaviour |
|---|---|
| platformer | walks on floors under gravity, jumps, climbs steps and slopes |
| topDown | moves freely in the plane with `MoveDir`, slides along walls; Face Movement turns the node |

![Motion 2D during Play: the Runtime fields show velocity, Grounded and the contacts](shots/motion-play.png)

## Floors, slopes and steps

Floors, walls and ceilings are told apart by the angle of the surface to Up Direction: a surface steeper than Max Slope is a wall. On a floor the character follows its slope without sliding down, and Snap To Ground keeps it on the floor when walking down a slope or a small step. Steps up to Step Height are climbed without jumping. Safe Margin is the gap kept to every surface so the next cast never starts inside one.

In the air a wall stops the movement into it and never lifts the character: a capsule or circle that meets the corner of a ledge slides off it instead of hanging there.

## Ledges

With **Ledge Climb** above 0, a character in the air that moves into a wall whose top is at most Ledge Climb above its feet climbs onto it: it rises to the top, steps onto the ledge and lands there, over **Climb Time** seconds. Higher walls are left alone. The climb runs on fixed steps like the rest of the motion: input, gravity and root motion are ignored during it, and the velocity stays at zero. Knockback (`AddVelocity`), `Stop`, `Dash` and `Teleport` end it at once.

**Climbing** is true during the climb and **Climbed** fires when it starts. To animate it, pass the flag to the Animator in `FixedUpdate`, as the player of the platformer example does:

```aes
a := node.Get<Animator>()
a.SetBool("Climbing", m.Climbing)
```

and give the controller a `Climb` state entered from `any` while `Climbing` is true.

## Jumps

Set **Jump Height** and the controller works out the jump speed from it and gravity; **Jump Speed** sets the speed directly instead. Releasing the button while rising cuts the jump short by **Jump Cut Multiplier**, so a tap gives a small hop.

Two windows make jumping forgiving. **Coyote Time** lets a jump work for a moment after walking off a ledge. **Jump Buffer** keeps a jump pressed in the air until the character lands. **Air Control** decides how much of the ground acceleration is available in the air.

Every field is listed on the [Motion 2D](/ref/gameplay.Motion2D.md) page.

## Platforms and bodies

With Moving Platforms the character rides on the body it stands on; Platform On Leave decides what happens to the platform's speed after a jump: `keep` adds it, `drop` loses it, `add` keeps only its horizontal part. With Push Bodies dynamic bodies do not stop the character, it pushes them.

`Dash(velocity, seconds)`, `AddVelocity` for knockback, `AddDisplacement(offset)` for root motion and scripted nudges, `Stop` and `Teleport` cover the rest. A displacement moves the character through walls and slopes like a move, on the next step, and leaves the velocity alone. The Runtime fields show the velocity, whether the character is grounded or touching a wall or ceiling, the floor normal and angle and the body it stands on.
