Hitboxes
A Hitbox 2D damages the hurtboxes inside its area after the physics step. Policy decides how often one target is hit:
| Policy | Hits |
|---|---|
| onEnter | every time the target enters |
| oncePerActivation | once per target until Activate |
| periodic | every Period seconds while they overlap |
Team and Friendly Fire keep attacks off their own side; Team -1 takes the team of the nearest Health above, so a sword on a child node fights for its owner and never hurts it. Knockback is a velocity for a target with Motion 2D and an impulse for a dynamic body; it turns with the hitbox node, so a flipped character pushes the other way. Knockback From Center pushes away from the hitbox instead.
A sword swing is one call:
if input.Pressed("Attack") {
Sword.Get<Hitbox2D>().Pulse()
}
Pulse() deals one round of damage in the next step, active or not; Activate() and Deactivate() switch a hitbox for the length of an attack. Hit(target, damage) fires for every target damaged.
Walk over the three spikes in the scene to compare the policies.

Try it
Change the example parameters and compare the result. Reset restores the initial scene.
Scene8 nodes
Scriptmain.aes
package demo
import (
"aego/debug"
"aego/input"
)
// Player walks over three spikes and shows its hit points.
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()
}
hp := node.Get<Health>()
p := node.WorldPosition()
debug.Text(Vec2{p.X - 0.6, p.Y - 1}, "hp " + string(hp.Current), Color{1, 1, 1, 1})
}
}
// Label writes Text above its node.
script Label {
@export var Text string
func Update(dt float) {
p := node.WorldPosition()
debug.Text(Vec2{p.X - 0.8, p.Y - 1}, Text, Color{0.85, 0.85, 0.85, 1})
}
}