Physics · function
heightfieldShape
Build a heightfield collision shape.
Explained in Your first game, Rigid bodies.
function heightfieldShape(field: Heightfield): ConvexShapeimport { heightfieldShape } from '@driftengine/physics';Parameters
| Parameter | Type | Description |
|---|---|---|
field | Heightfield |
In depth
Returns a ConvexShape whose triangles names the field — so every existing test of "is this a
mesh" answers yes and every rule that follows from it holds: refused as a kinematic collider,
refused on anything but a static body, and given a static body's own zero mass tensor. Its
vertices are the eight corners of the field's bounds, so the broad phase measures the right box,
and its faceNormals and edgeDirs are empty for the reason meshShape gives: a field has no
separating axes worth enumerating, and handing the kinematic sweep the box's three would make a
hillside a solid brick.
The heights are kept and not copied, the same bargain meshShape makes with a level's
vertices: a field is the thing being avoided allocating twice. A caller must not go on mutating
them, which is stated here because nothing enforces it — and unlike a mesh there is nothing to
rebuild if they do, so a caller who wants a changing field may mutate and the collider follows.