Physics

Access to the physics scene

.constructor(engine: WonderlandEngine) ⇒ Physics 

ParamTypeDescription
engineWonderlandEngine

.engine: WonderlandEngine 

Hosting engine instance.

.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:

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

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.