Physics · class

CompositeSurface

Explained in Your first game, Rigid bodies.

class CompositeSurface implements GroundSurface
import { CompositeSurface } from '@driftengine/physics';

Constructor

new

constructor(surfaces: readonly GroundSurface[])
ParameterTypeDescription
surfacesreadonly GroundSurface[]

Accessors

NameTypeDescription
partsgetreadonly GroundSurface[]The floors this is made of.
More

Exposed because "two of my floors are in the same column" is a question only the parts can answer, and it is one a consumer has to be able to ask. Two walkable surfaces overlapping with millimetres between them is invisible to every gameplay check — sample picks one and both readings look sane — while on screen the depth buffer cannot separate them and the pair flickers against each other as the camera turns. Composed, that information is gone.

Methods

sample

sample(x: number, z: number, out: SurfaceHit, atY?: number): boolean

Ask every part and keep the best answer.

ParameterTypeDescription
xnumber
znumber
outSurfaceHit
atY?number
More

atY is what makes this correct rather than arbitrary. Without a reference height the only available rule is "highest wins", which teleports a character on the low line of a split up onto the high one the moment the two overlap.

sampleBand

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

See GroundSurface.sampleBand: the highest floor any part puts in the band.

ParameterTypeDescription
xnumber
znumber
outSurfaceHit
loYnumber
hiYnumber
More

The one query where composing surfaces costs nothing in fidelity — a band is a filter, so asking every part and keeping the highest answer is the same answer a single surface holding all of them would give.