Skip to content

Time an attack and its effects to the animation ​

Make the arrow leave, or the blow land, at an exact moment of the attack clip, and play an effect or a sound at other moments of it. An example archer:

  • the arrow leaves 20% into the attack animation;
  • a frost glow plays on the bow 10% in, before the shot.

How the timing works ​

Two things are set separately, and the game lines them up:

WhatWhere it livesIn
When the attack happens (the damage lands, or the arrow leaves)the unit type's attack: damagePointseconds, in the rules (data.json from the editor)
Where that moment is in the animationthe clip's hit marka share of the clip, 0 to 1, in the look (looks.json)

The game stretches the clip around its hit mark: the part before the mark is played over the attack's windup (damagePoint, shorter at a higher attack speed), and the part after over the rest of the swing (recovery, else the rest of the attack's period). The release frame you marked therefore shows exactly when the arrow leaves, at any attack speed. A part is played at most four times faster or slower than it was made. A clip with no hit mark has its blow two fifths in.

Every other mark (an effect, a sound, a footstep) is a share of the clip too, and moves with the stretching. With the blow at 20%, a mark at 10% lands halfway through the windup.

In the editor ​

  1. Open the Animation panel (Window › Animation) and pick the archer under Model. Pick its attack clip in the list at the left.
  2. Click the timeline's ruler at 20% of the clip. The bar shows where the playhead is.
  3. Above the timeline, press Hit (or M). The red hit mark appears on the ruler.
  4. Click the ruler at 10%, open Effect… above the timeline and pick the effect (or type a new name). A fx:<effect> mark appears.
  5. The Marks tab at the right lists every mark: rename it, type its time in seconds, go to it, or take it away. Drag a mark on the ruler to move it.
  6. Press Write the look (in the bar, or the Marks tab) to keep the marks in looks.json.
  7. Line the attack up with the clip: look into the unit type (Content: right-click › Look into it), open the Attack tab and press From the clip. The attack's damagePoint (and recovery) are set from the hit mark. Press Keep in the Data panel to write them into data.json.

The Attack tab plays the swing at a dummy, so you can watch the blow and the effects land.

In code ​

ts
// src/rules.ts: the attack, in seconds
attacks: [{ acquisitionRange: 8, damagePoint: 0.3, projectileSpeed: 20 }]

// src/view.ts: the look, the clip's marks as shares of it
looks: {
	archer: {
		height: 1.8,
		model: {
			src: 'units/archer.glb',
			scale: 1,
			clips: {
				Bow_Shoot: {
					marks: [
						{ name: 'fx:bowFrost', at: 0.1 }, // the frost, halfway through the windup
						{ name: 'hit', at: 0.2 } // the arrow leaves: lands on damagePoint
					]
				}
			}
		},
		shapes: [],
		attacks: [{ clip: 'Bow_Shoot' }]
	}
}

The editor writes the same into looks.json, under the type's model.clips.

What a mark can do ​

MarkDoes
hitWhere the blow lands, or the shot leaves: the clip is fitted so this lands on damagePoint. A melee blow's sound plays here (a shot is heard where it lands). One per clip
footA footstep: the type's footstep sound
fx:<name>Plays one of the game's effects on the unit
sound:<name>Plays one of the game's sounds at the unit
any other nameYour look's onMark(entity, { name, clip }) hears it: return true to say you handled it

Marks are only for what is seen and heard. The simulation does not read them: damage, a slow, a buff all happen at damagePoint, in the rules. Games stay in step because the rules keep their own numbers.

An effect on the bow itself, as the arrow leaves ​

An fx: mark plays its effect on the unit. To play it at a point of the model instead (the bow hand), at the moment the shot leaves, use the attack look's launch and from:

ts
attacks: [{ clip: 'Bow_Shoot', launch: { fx: 'bowFrost' }, from: 'handslot.l' }]

In the editor this is the Attack tab's Launch and From. Use a mark for a moment before or after the shot; use launch for the shot itself.

See also ​