Skip to content

Destruction and debris ​

How things die on screen: the death clip, effects, a building crumbling or toppling, pieces flying, the body, the ruins left, and how a unit looks as it's hurt and hit. All of it is for the screen only, and every player who sees it sees the same.

Quick start ​

ts
'orc.burrow': {
	model: { src: 'burrow.glb', scale: 1, points: { roof: { offset: [0, 3, 0] } } },
	death: {
		fx: [{ fx: 'explosion', params: { size: 1.5 } }, { fx: 'smoke', delay: 0.4 }],
		sound: 'collapse',
		collapse: { look: 'crumble', dust: true, pieces: 20 },
		pieces: { fx: 'smoke-trail', share: 0.3, landed: 'dust' },
		remains: { model: 'ruins/burrow_ruins.glb', time: 60 }
	},
	damaged: [
		{ below: 0.5, fx: 'smoke', at: 'roof' },
		{ below: 0.25, fx: 'fire', at: 'roof' }
	]
}

A unit look (in GameView.units.looks). The burrow smokes under half health and burns under a quarter. When it dies it explodes, crumbles into 20 pieces of itself in a cloud of dust, some pieces trailing smoke, and leaves ruins for a minute.

Common tasks ​

Step by step, with a hut to knock down: Break a building to pieces when it is destroyed. How it goes up: Build a building.

Die differently by how it was killed ​

The rules say how (death.how: 'burnt', 'crushed'…). Set it on the attack (AttackDef.how), the ability (AbilityDef.how) or a damage effect, then give the look a how entry:

ts
death: {
	collapse: 'crumble',
	how: { burnt: { fx: 'fire', collapse: 'sink' }, shattered: { shatter: 12 } }
}
// on an attack, decided per hit
how: (hit) => (hit.crit ? 'shattered' : 'cut')

In code: world.damage(target, amount, source, { how }). The death hook has the last say (death.how = 'exploded').

Sink when sold, crumble when destroyed ​

The rules give a reason with the kill; onDeath reads it.

ts
// rules
world.kill(tower, undefined, false, 'sold')
// look
onDeath: (entity, death) => (death.reason === 'sold' ? { collapse: 'sink', fx: undefined } : undefined)

Reasons: damage, killed (world.kill), cancelled, expired, depleted, felled, removed, or your own word.

Look hurt as health drops ​

damaged stages turn on while health is under below, and off again as it heals (a repaired building stops smoking).

ts
damaged: [
	{ below: 0.5, fx: 'smoke', at: 'roof' },
	{ below: 0.25, fx: 'fire', at: ['roof', 'door'], sound: 'whoosh' },
	{ below: 0.1, model: { src: 'burrow_burnt.glb', scale: 1 }, clip: 'Sway' }
]

Or a function: damaged: (entity, health) => (health < 0.3 && entity.state.buffs?.includes('frozen') ? [{ id: 'ice', below: 1, fx: 'frost' }] : []).

React to each hit ​

onHit on a look: an effect where it's struck, a flash, a shake, a sound, or decided per hit:

ts
onHit: (entity, hit) => (hit.attack ? { fx: 'spark-burst', flash: [1, 1, 1] } : undefined)

Leave a body ​

corpse: { lie, sink, fade, decal } sets how long a unit's body lies (2.5 s), then sinks (1.5 s) or fades, with a ground mark under it.

Burning ​

In a game with the burning pack (burningPack), what the rules set alight carries onFire, and its look's burning says what plays on it until it burns down: the ready-made fire at its middle (or at the points at names), a sound as it catches, a colour over it (tint) and a char that darkens it to near black as it burns (char). The kind of burning the rules name (how: burnt, or a game's withered, frozen) picks the look's how entry, and its end is the death's how entry for the same word.

ts
tree: {
	burning: { at: 'crown', sound: 'crackle', how: { frozen: { fx: 'frost', char: [0.7, 0.85, 1], light: false } } },
	death: { how: { burnt: { collapse: 'sink', fx: 'dust' }, frozen: { shatter: 12 } } }
}

Trees burn as models, never as pictures far off (a charred tree is drawn at its lightest model there), and their char is a colour of each copy, not a material a tree. In a forest fire only the nearest the camera play their effect (GameView.units.burning.most, 40) and the nearest few give light (lights, 6); the others only char. A tree that burnt down falls as felled (leaves: 'felled'), sinks into the ground in smoke where it burnt away ('nothing'), or as its death.how.burnt says. See Let trees burn. Grass and bushes burn as cells of their own layer, with ruin and growing back: see Set grass on fire.

A burning tree is not woken, so the rules look at it in the pack alone: a forest of 30,000 trees costs nothing more a tick with the pack on and nothing alight. With 2,000 trees alight it is measured by npm run bench -- burning (a 256 × 256 forest, eight teams of four soldiers, a wind): see the numbers its run prints.

Editor ​

  1. Select a unit type and open the Inspector's Model view (or Set up as a unit).
  2. Death tab: pick a how and a side it's hit from, then set the clip, effects, pieces, body, collapse and remains. It plays on the model.
  3. Going up tab (buildings): scrub construction, Put it up, Call it off, Its upgrade.
  4. Damage tab: drag the health slider to see each damaged stage; add stages with an effect, clip or model.
  5. Changes go into looks.json at once; As the code's removes them.

Reference ​

UnitLook.death ​

FieldWhat it is
clipThe clip it falls with (the model's death when left out)
fxEffects as it dies: by name or inline, at a model point, after delay, with knobs
soundA game sound from where it died
shatter, debris, strengthBreaks into shatter pieces of itself, or the debris pieces given, flung away from the killer with strength (where physics loaded)
piecesAn effect on a share of the pieces as they fly, and one where each lands (landed)
corpseA unit's body: lie (2.5), then sink (1.5) or fade seconds; a decal under it
collapseA building: sink, crumble, explode, topple (away from the killer); time, dust, pieces
remainsLeft where it stood: model for time seconds, then sinking (fade, scale, decal)
keep, noneKept for your code (client.renderer.kit.letGo(id) lets it go), or gone at once
howOverrides for a death of that how

A short word works too: 'fall', 'shatter' (a dozen pieces), 'debris' (the look's debris), 'none', 'keep'.

AlsoWhat it does
onDeath(entity, death) => fields over death, per death
GameView.units.deathForDecides for any unit, before its type
damagedStages by health share: below, fx, at, sound, model, clip
burningWhile it burns (the burning pack): fx, at, params, sound, light, tint, char, by how
onHitPer hit: fx (at a point or its middle), flash, shake, sound

Notes ​

  • The screen gets how, reason and the blow's tags with the death (SessionEvent death).
  • Remains are only drawn. Rubble that blocks the way, gets cleared by workers or gives stone is a unit spawned by the rules in the death hook.
  • Damaged looks and hits are the client's damage renderer; replace it with GameView.replace.damage.
  • What burns is the client's burning renderer (a look's BurningLook); replace it with GameView.replace.burning.
  • In code: editor.saveLook(type, { death }), editor.looksEntry(type), laidFile(view, LOOKS_FILE); the editor's look tabs play them on a ModelStage.
  • In the example: melee buildings smoke, burn and crumble (apps/example/src/games/melee/view/looks.ts).