FERRETGame engine over Babylon.js
Ferret

Destruction

Skill ferret-destruction · download all skills · SKILL.md

When to use#

Parts that must dent, crack, snap, shatter or come off: cars, windows, fences, crates, brick walls. Not for the whole-body break and joints of the simple kind (ferret-physics-strength), not for blasts and craters (ferret-physics-combustion-explosions, whose events it reads).

The model#

A hit becomes energy 1/2 mu v^2 (1 - e^2); a failure model of the part's material kind spends it into a ledger (crush, fracture, kinetic, heat, sound) that balances. Ductile parts crush along a force-depth curve, glass breaks by plate stress, wood by bending, stone by cells. Rolling and overturning come out of the rigid dynamics. A style changes numbers or swaps models; physical is the default.

Steps#

  1. const service = new DestructionService({ maxPieces }); a thing: defineThing(block) (parts, links, crush zones, glass panes) or defineCar(id, 'crown-victoria-cpd87' | 'corvette-c4-87-conv', nodes).
  2. Physics: register destruction(service) on the host (needs a rigid-body kernel for boxes and cars), bind(id, body).
  3. Look: installDestructionView(world, service, { nodeOf }) (dents, crack stars, shards, detached parts, one sound per break).
  4. Behaviour: destruction.style {scope:'world'|'level'|'zone'|'entity', name}; presets physical, cartoon, hollywood, brittle-world, rigid-world; your own by destruction.define.
  5. Ask why: destruction.explain {entity} (style, energy in, where it went, or why nothing broke).
  6. Net and save: send the break record, replay(record) on the peer; save() / load().
  7. Motion language: linkMotion(service, bridge), then (destruction-break who part energy x y z), (destruction-style who name), sensors (damage who), events destruction:*.
  8. Look at it: ?destruction viewer (destruction.stage, .camera, .screenshot, .capture, .launch).

Check afterwards#

balanced(outcome.ledger) is true for every hit; the same seed gives the same pieces; a replay equals the owner's outcome; the piece cap holds; a car at rest stays at rest.

What usually goes wrong#

  • Nothing breaks: the kernel has no rigid bodies (light kernel moves spheres only), or the style is rigid-world, or the energy is below what the part holds (explain).
  • A car is driven twice: it is bound to a body; the view skips bound things by default.
  • Too many shards: far and unseen breaks make none; raise maxPieces only on purpose.
  • A style does not conserve: conserve:false is shown by explain; that is the style's choice.
  • A model name in override is unregistered: register it with StyleBook.registerModel first.

Files#

  • reference/destruction.md — Cars that crumple and roll, glass that cracks and shatters, planks that snap, bricks and crates that fly apart; by physics unless a style says otherwise (cartoon, hollywood, rigid-world); the energy ledger, replication by seed, the ?destruction viewer.
  • reference/api-destruction.md — every export of @ferret/destruction with signature and doc comment
  • reference/api-destruction-2.md — every export of @ferret/destruction with signature and doc comment
  • reference/api-destruction-3.md — every export of @ferret/destruction with signature and doc comment