Physics · interface

GroundSurface

Anything that can answer "where is the ground here?".

Explained in Your first game, Rigid bodies.

interface GroundSurface
import type { GroundSurface } from '@driftengine/physics';

In depth

The seam a controller depends on, rather than on RibbonSurface itself: a game with heightmap terrain, or a test with three lines of arithmetic, is a valid ground surface and neither should have to build a spline to say so.

Methods

sample

sample(x: number, z: number, out: SurfaceHit, atY?: number): boolean
ParameterTypeDescription
xnumber
znumber
outSurfaceHit
atY?numberHeight of whatever is asking, so a route that passes over itself can answer with the deck under them rather than the highest one in the column. Omitted means "the highest", which is right for a caller that has no position — a generator placing a lamp, say.

sampleBand

sampleBand(x: number, z: number, out: SurfaceHit, loY: number, hiY: number): boolean

The highest floor in this column whose face lies in [loY, hiY), exactly.

ParameterTypeDescription
xnumber
znumber
outSurfaceHit
loYnumber
hiYnumber
More

A second question, not a variant of the first, and the reason it cannot be expressed as one: sample scores candidates by nearness to the asker and breaks ties against whatever is above them, because what you are standing on is the thing under your feet. "Is there a floor in the way" asks about a band that is entirely above the asker, so that scoring is pointed at the exact answer wanted — a deck a metre up loses to the deck underfoot and the caller is told the column is clear.

So this is a filter and not a score: every face in the band qualifies, the highest wins, and nothing outside the band can outrank anything inside it. No reference height, no tie-break, nothing to tune.

Half-open on purpose. A caller testing "between my step ceiling and my head" owns both of its own bounds, and a face exactly at head height is one the body passes under rather than into.