Physics
Access to the physics scene
.constructor(engine: WonderlandEngine) ⇒ Physics
| Param | Type | Description | 
|---|---|---|
| engine | WonderlandEngine | 
.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.
| Param | Type | Description | 
|---|---|---|
| o | Readonly<NumberArray> | Ray origin. | 
| d | Readonly<NumberArray> | Ray direction. | 
| groupMask | number | Bitmask of physics groups to filter by: only objects that are part of given groups are considered for the raycast. | 
| maxDistance | number | Maximum inclusive hit distance. Defaults to 100. |