FERRETGame engine over Babylon.js
Ferret

Walkers: standing on things under physics

Skill ferret-physics-walkers · download all skills · SKILL.md

When to use#

Always, for anything that stands or walks: a crowd on a beach and a mole, men on a ship's deck, crew walking about a lifeboat, NPCs on a moving platform. Every Ferret scene rests on the engine's physics unless it says otherwise: nobody is in the air, below a deck or inside a hull; a man in the air falls into the water, a man on a deck rests on it. Do not write y = table[x][z], do not interpolate heights between points by hand, do not move people on paths that can leave them off the ground.

The model#

Walkers (in @ferret/physics) holds Supports and steps Walkers: carry with the support, move by the wanted (dx, dz) if ground and walls allow (slide along walls), step up 0.45 and down 0.6, otherwise fall with g, splash and sink in water, land on the next support. FieldSupport (a function), GridSupport (cells read off a model, own frame, moves, range), StripSupport (a gangway, lies on over its ends, passes walls).

Steps#

  1. One Walkers for the scene, with the ground as a FieldSupport and water: () => seaLevel.
  2. A ship, boat or platform: read its model with rays on a grid (several layers per ray, in its own frame) into a GridSupport, give it a frame (world <-> node) and a range; push it into walkers.supports, remove it when the craft goes.
  3. A gangway or ramp: a StripSupport laid from the quay edge to the deck in the same step that sends the men over it.
  4. Each person gets a Walker (place on the ground, mount on a moving deck); each step: walkers.step(w, dt, dx, dz, true) and copy x, y, z out. The AI decides where to go; the physics decides where he can be.
  5. React to splash, blocked, swim: give up a target when blocked; a man afloat (w.swim) swims toward the shallows by passing (dx, dz); never move anyone by hand.
  6. Test with the pure Walkers (no engine): falls onto a deck, off an edge into water, a wall stops, a rolling deck carries, a gangway is crossed.

Check afterwards#

A probe over a few minutes of the running scene: nobody in the air, nobody below the surface under his feet, men over the side only when the scene meant it; screenshots of the decks and the gangway.

What usually goes wrong#

  • Men fall through a moving deck: its matrix and range were not updated together this frame.
  • Men left in the air when the ship sails: they stood on a world-fixed gangway; the support with a frame wins ties, make the gangway overlap the deck.
  • Crew fall into a hole in the model: the target needs a path the support does not have; use waypoints, careful: true, give up on blocked.
  • Men step off the gangway sideways at its foot: they were told to walk along the rail; send them inboard first.
  • A scene with hand-placed heights "works" until something moves under it: that is the bug, not the scene.

Files#