Physics · class

BoxSurface

Explained in Your first game, Rigid bodies.

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

Constructor

new

constructor(boxes: readonly SurfaceBox[])
ParameterTypeDescription
boxesreadonly SurfaceBox[]

Accessors

NameTypeDescription
countgetnumber

Methods

sample

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

The highest pad whose footprint contains the column.

ParameterTypeDescription
xnumber
znumber
outSurfaceHit
atY?number
More

Highest rather than nearest, because pads never overlap in a way where the lower one is the answer — a flight of steps is monotone — and "highest" needs no reference height, which keeps this usable from a plain GroundSurface call.

A linear scan: a day's route carries a few dozen pads, and a scan over thirty boxes inside a fixed tick costs less than the branch needed to skip it. Allocation-free either way.

sampleBand

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

See GroundSurface.sampleBand: the highest pad whose top is in the band.

ParameterTypeDescription
xnumber
znumber
outSurfaceHit
loYnumber
hiYnumber