Physics

Access to the physics scene

Static Members

Properties

Methods


Constructor

.constructor(engine: WonderlandEngine) ⇒ Physics

ParamTypeDescription
engineWonderlandEngine

Properties

.engine: WonderlandEngine

Hosting engine instance.



Methods

.rayCast(o: Readonly<NumberArray>, d: Readonly<NumberArray>, groupMask: number, maxDistance: number) ⇒ RayHit

Cast a ray through the scene and find intersecting physics components.

The resulting ray hit will contain up to 4 closest ray hits, sorted by increasing distance.

Example:

const hit = engine.physics.rayCast(
    [0, 0, 0],
    [0, 0, 1],
    1 << 0 | 1 << 4, // Only check against physics components in groups 0 and 4
    25
);
if (hit.hitCount > 0) {
    const locations = hit.getLocations();
    console.log(`Object hit at: ${locations[0][0]}, ${locations[0][1]}, ${locations[0][2]}`);
}

Returns: The RayHit instance, cached by this class.

Note: The returned RayHit object is owned by the Physics instance and will be reused with the next rayCast call.

ParamTypeDescription
oReadonly<NumberArray>Ray origin.
dReadonly<NumberArray>Ray direction.
groupMasknumberBitmask of physics groups to filter by: only objects that are part of given groups are considered for the raycast.
maxDistancenumberMaximum inclusive hit distance. Defaults to 100.