Physics · function
coveredAbove
Whether anything solid stands over this column, between two heights.
Explained in Your first game, Rigid bodies.
function coveredAbove(surface: GroundSurface, x: number, z: number, fromY: number, toY: number, scratch: SurfaceHit): booleanimport { coveredAbove } from '@driftengine/physics';Parameters
| Parameter | Type | Description |
|---|---|---|
surface | GroundSurface | |
x | number | |
z | number | |
fromY | number | |
toY | number | |
scratch | SurfaceHit |
In depth
The general question, of which "should rain fall here" is one caller. A surface answers three
things and only two of them had names: where the ground is, whether a floor is in the way, and —
the one this is — whether the sky is visible from a point. That third question is asked by more
than weather, and it is asked constantly: rain and snow that stop under a canopy, a puddle that
only forms where the sky reaches, a shaft of sun that should not appear indoors, an agent
deciding whether it is worth taking shelter, a plant that grows toward light. Every one of those
is sampleBand over the column above you, and every consumer that wants one would otherwise
discover that for themselves.
A hole is a hole, for free. This is the property worth stating, because it is what usually
separates a convincing effect from a stamped-on one: the answer comes from whether the surface
has a face in that column, so a roof with a gap in it, a RibbonSurface with a stretch of
holes, a run of pads with air between them, or a bounded heightfield past its own edge all let
the sky through in exactly the places they look like they should. Nothing describes the opening
twice and nothing can disagree with the geometry it was cut from.
toY is where the caller stops caring — a cloud base, the top of a level. Half-open like
sampleBand, so a face exactly at toY is above the question rather than in it.