Aego Русский

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.

Starts the scene; open the example parameters to experiment.
Open in AegoDownload example project
Scene3 nodes
Attack
Transform
position[-1.4, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")tintColor#ef4444ffsizeVec2[1, 1.5]orderint1
Hitbox 2D
areaRect[-0.5, -0.75, 1, 1.5]damageint0teamint1policyenumoncePerActivationactivebooltrue
Target
Transform
position[0, 0]rotation0scale[1, 1]
Sprite Renderer
spriteTextureasset("ae900000000000000000000000000010")tintColor#0dcc40ffsizeVec2[2.4, 2]
Hurtbox 2D
areaRect[-1.2, -1, 2.4, 2]multiplierfloat1activebooltrue
Camera
Transform
position[0, 0]rotation0scale[1, 1]
Camera 2D
zoomfloat40clearColorColor#111827ffscaleenumfitVirtualvirtualVec2[960, 540]activebooltrue
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

NameTypeDefaultDescription
AreaRect(-0.5, -0.5, 1, 1)

Rectangle in this node's space.

Shapeenumbox

box uses the rectangle; circle uses the circle inside it.

one of: box, circle
Damageint1

Damage per hit before the hurtbox multiplier.

≥ 0
KnockbackVec2(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 Centerboolfalse

Pushes away from the hitbox centre instead, with the length of Knockback.

Teamint-1

Team of the attack; -1 takes the team of the nearest Health above.

≥ -1
Friendly Fireboolfalse

Also hits targets of the same team.

PolicyenumoncePerActivation

onEnter hits on every entry, oncePerActivation hits each target once until Activate, periodic hits every Period while overlapping.

one of: onEnter, oncePerActivation, periodic
Periodfloat0.5

Seconds between hits for the periodic policy.

≥ 0
Activebooltrue

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.