Physics
Access to the physics scene
Static Members
- .constructor(engine) ⇒ Physics
Properties
Methods
Constructor
.constructor(engine: WonderlandEngine) ⇒ Physics
| Param | Type | Description |
|---|---|---|
engine | WonderlandEngine |
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.
| 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. |