Physics · class
BoxSurface
Explained in Your first game, Rigid bodies.
class BoxSurface implements GroundSurfaceimport { BoxSurface } from '@driftengine/physics';Constructor
new
constructor(boxes: readonly SurfaceBox[])| Parameter | Type | Description |
|---|---|---|
boxes | readonly SurfaceBox[] |
Accessors
| Name | Type | Description |
|---|---|---|
countget | number |
Methods
sample
sample(x: number, z: number, out: SurfaceHit, atY?: number): booleanThe highest pad whose footprint contains the column.
| Parameter | Type | Description |
|---|---|---|
x | number | |
z | number | |
out | SurfaceHit | |
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): booleanSee GroundSurface.sampleBand: the highest pad whose top is in the band.
| Parameter | Type | Description |
|---|---|---|
x | number | |
z | number | |
out | SurfaceHit | |
loY | number | |
hiY | number |