Character motion
Motion 2D moves a character with a kinematic Rigid Body 2D. 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 |

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:
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 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.
Try it
Change the example parameters and compare the result. Reset restores the initial scene.
Scene7 nodes
Scriptmain.aes
package demo
import "aego/input"
// Player walks with A/D or the arrows and jumps with Space, W or Up.
script Player {
func Update(dt float) {
m := node.Get<Motion2D>()
x := 0.0
if input.Down(input.KeyA) || input.Down(input.KeyLeft) {
x -= 1
}
if input.Down(input.KeyD) || input.Down(input.KeyRight) {
x += 1
}
m.Move(x)
if input.KeyPressed(input.KeySpace) || input.KeyPressed(input.KeyW) || input.KeyPressed(input.KeyUp) {
m.Jump()
}
if input.KeyReleased(input.KeySpace) || input.KeyReleased(input.KeyW) || input.KeyReleased(input.KeyUp) {
m.JumpReleased()
}
}
}
// Lift moves a kinematic platform up and down.
script Lift {
@export var Travel Vec2 = Vec2{0, -3}
@export var Period float = 4
var t float
var start Vec2
func Ready() {
start = node.Transform2D().Position
}
func FixedUpdate(dt float) {
t += dt
phase := t / Period
k := phase - float(int(phase))
if k > 0.5 {
k = 1 - k
}
k *= 2
body := node.Get<Body2D>()
body.MoveTo(Vec2{start.X + Travel.X*k, start.Y + Travel.Y*k}, 0)
}
}