Hitbox 2D
Damages hurtboxes inside its area, once per target per activation, on every entry or periodically.
component gameplay.Hitbox2D
On this page
Try it
Damage an overlapping target
The red hitbox overlaps the green target's hurtbox. With Damage 0 the target keeps all 10 health points.
Set Damage to 3. The scene restarts and the real hitbox deals one hit: the target has 7 health points and turns orange. Reset restores the zero-damage attack.
Scene3 nodes
Scriptmain.aes
package demo
// The target changes color only after its actual Health takes damage.
script DamageIndicator {
func Update(dt float) {
hp := node.Get<Health>()
if hp.Current < hp.Max {
node.Get<SpriteRenderer>().Tint = Color{1, 0.5, 0.05, 1}
} else {
node.Get<SpriteRenderer>().Tint = Color{0.05, 0.8, 0.25, 1}
}
}
}
Fields
| Name | Type | Default | Description |
|---|---|---|---|
| Area | Rect | (-0.5, -0.5, 1, 1) | Rectangle in this node's space. |
| Shape | enum | box | box uses the rectangle; circle uses the circle inside it. one of: box, circle |
| Damage | int | 1 | Damage per hit before the hurtbox multiplier. ≥ 0 |
| Knockback | Vec2 | (0, 0) | Push on a hit: velocity in units per second for a Motion 2D target, impulse for a dynamic body. Turns with the node. |
| Knockback From Center | bool | false | Pushes away from the hitbox centre instead, with the length of Knockback. |
| Team | int | -1 | Team of the attack; -1 takes the team of the nearest Health above. ≥ -1 |
| Friendly Fire | bool | false | Also hits targets of the same team. |
| Policy | enum | oncePerActivation | onEnter hits on every entry, oncePerActivation hits each target once until Activate, periodic hits every Period while overlapping. one of: onEnter, oncePerActivation, periodic |
| Period | float | 0.5 | Seconds between hits for the periodic policy. ≥ 0 |
| Active | bool | true | Off deals no damage. |
Methods
Activate method
func (Hitbox2D) Activate()
Starts a new attack: targets hit before can be hit again.
Deactivate method
func (Hitbox2D) Deactivate()
Stops dealing damage.
Pulse method
func (Hitbox2D) Pulse()
Deals one round of damage in the next step, active or not.
Signals
Hit signal
signal Hit(target NodeRef, damage int)
Fires for each target damaged.
Related guides
- Hitboxes A Hitbox 2D damages the hurtboxes inside its area after the physics step.
- Gameplay kit The gameplay module adds the parts most 2D games rebuild by hand: a character controller, hit points, hitboxes and hurtboxes, kill zones, checkpoints with respawn, pickups and timed removal.