wired:physics
Rigid-body simulation queries and velocity/force control.
Every peer runs the simulation locally, while the document's current holder is authoritative and replicates body motion to other peers.
Interface simulation
Uses vec3, ray, document-id, prim-id, prim-ref, error, document.
ray-hit
target: prim-ref | Hit prim. |
point: vec3 | |
normal: vec3 | Unit surface normal facing back along the ray. |
distance: f32 |
ray-filter
Colliders to ignore during a raycast.
exclude-local-agent: bool | Exclude the local user's own body. |
exclude-documents: list<document-id> | Exclude all colliders in these documents (max 64). |
body-velocity
Instantaneous body velocity in the calling script's document frame.
linear: vec3 | Linear velocity in meters per second. |
angular: vec3 | Angular velocity in radians per second about each axis. |
raycast
raycast: func(ray: ray, max-distance: f32, filter: ray-filter) -> result<option<ray-hit>, error>Casts ray up to max-distance in the calling script's document frame
and returns the closest hit.
velocity
velocity: func(document: borrow<document>, prim: prim-id) -> result<body-velocity, error>Returns a dynamic body's velocity. Fails with not-ready before the body
enters simulation, or invalid-argument for non-dynamic bodies.
set-velocity
set-velocity: func(document: borrow<document>, prim: prim-id, linear: option<vec3>, angular: option<vec3>) -> result<_, error>Sets linear and/or angular velocity on a dynamic body in the calling
script's document frame (none leaves that component unchanged).
set-force
Applies a persistent force in the calling script's document frame on every physics step until changed; pass zero to clear.
Source
/// Rigid-body simulation queries and velocity/force control.
///
/// Every peer runs the simulation locally, while the document's current holder
/// is authoritative and replicates body motion to other peers.
package wired:physics;
interface simulation {
use wired:core/math.{vec3, ray};
use wired:core/ids.{document-id, prim-id, prim-ref};
use wired:core/error.{error};
use wired:scene/document.{document};
record ray-hit {
/// Hit prim.
target: prim-ref,
point: vec3,
/// Unit surface normal facing back along the ray.
normal: vec3,
distance: f32,
}
/// Colliders to ignore during a raycast.
record ray-filter {
/// Exclude the local user's own body.
exclude-local-agent: bool,
/// Exclude all colliders in these documents (max 64).
exclude-documents: list<document-id>,
}
/// Instantaneous body velocity in the calling script's document frame.
record body-velocity {
/// Linear velocity in meters per second.
linear: vec3,
/// Angular velocity in radians per second about each axis.
angular: vec3,
}
/// Casts `ray` up to `max-distance` in the calling script's document frame
/// and returns the closest hit.
raycast: func(ray: ray, max-distance: f32, filter: ray-filter) -> result<option<ray-hit>, error>;
/// Returns a dynamic body's velocity. Fails with `not-ready` before the body
/// enters simulation, or `invalid-argument` for non-dynamic bodies.
velocity: func(document: borrow<document>, prim: prim-id) -> result<body-velocity, error>;
/// Sets linear and/or angular velocity on a dynamic body in the calling
/// script's document frame (`none` leaves that component unchanged).
set-velocity: func(
document: borrow<document>,
prim: prim-id,
linear: option<vec3>,
angular: option<vec3>,
) -> result<_, error>;
/// Applies a persistent force in the calling script's document frame on every
/// physics step until changed; pass zero to clear.
set-force: func(document: borrow<document>, prim: prim-id, force: vec3) -> result<_, error>;
}