Attack with a hit frame
The damage of an attack belongs to one frame of its clip, not to the button press: put a gameplay event on that frame and pulse a hitbox when it arrives.
anim version=1 length=0.3 {
frames "" {
sprites=[asset("…swing_0"), asset("…swing_1"), asset("…swing_2")]
durations=[0.06, 0.06, 0.18]
}
event t=0.1 name="Hit" payload=1 {}
}
The controller enters the attack from any state on a trigger and leaves after one pass:
transition "any" to="Hit" interrupt=true {
cond "Attack" {}
}
transition "Hit" to="Idle" exitTime=1 duration=0.05 {}
The script presses the trigger and turns the event into damage:
func Ready() {
hit = anim.EventID("Hit")
}
func OnAnimEvent(id int, payload float) {
if id == hit {
Slash.Get<Hitbox2D>().Pulse()
}
}
- Give the Hitbox 2D
active=falseandpolicy=oncePerActivation:Pulsedeals one round, so each attack hits each target once. - A second press during the attack does nothing, since an
anytransition never leaves its own target. - The event is a gameplay event: it fires on the fixed step that crosses it, the same on every replay.
- Keep the transition into the attack without
duration: with the default event policy an event during a blend belongs to the side with more weight, and an event early in a fade-in would go to the outgoing state.