Header menu logo PhysicsSandbox

Prelude Module

Auto-opened convenience module re-exporting all scripting functions. Referencing the assembly makes all helpers, builders, and lifecycle functions available without qualification.

Functions and values

Function or value Description

batchAdd arg1 arg2

Full Usage: batchAdd arg1 arg2

Parameters:
Returns: BatchResult

Sends commands in auto-chunked batches of 100. Returns per-command success/failure results.

arg0 : Session
arg1 : SimulationCommand list
Returns: BatchResult

bouncyMaterial

Full Usage: bouncyMaterial

Returns: MaterialProperties

Bouncy material: friction 0.4, high recovery 8.0, spring 60 Hz / 0.5 damping.

Returns: MaterialProperties

makeAngularMotorCmd id bodyA bodyB targetVelocity maxForce

Full Usage: makeAngularMotorCmd id bodyA bodyB targetVelocity maxForce

Parameters:
    id : string
    bodyA : string
    bodyB : string
    targetVelocity : float * float * float
    maxForce : float

Returns: SimulationCommand

Builds an angular-motor constraint — drives rotation.

id : string
bodyA : string
bodyB : string
targetVelocity : float * float * float
maxForce : float
Returns: SimulationCommand

makeBallSocketCmd id bodyA bodyB offsetA offsetB

Full Usage: makeBallSocketCmd id bodyA bodyB offsetA offsetB

Parameters:
    id : string - Unique constraint ID.
    bodyA : string - First body ID.
    bodyB : string - Second body ID.
    offsetA : float * float * float - Local offset on body A (x, y, z).
    offsetB : float * float * float - Local offset on body B (x, y, z).

Returns: SimulationCommand

Builds a ball-socket constraint — free rotation around anchor.

id : string

Unique constraint ID.

bodyA : string

First body ID.

bodyB : string

Second body ID.

offsetA : float * float * float

Local offset on body A (x, y, z).

offsetB : float * float * float

Local offset on body B (x, y, z).

Returns: SimulationCommand

makeBoxCmd id pos halfExtents mass

Full Usage: makeBoxCmd id pos halfExtents mass

Parameters:
    id : string - Unique ID. Use nextId "box" for auto-generated.
    pos : float * float * float - Position (x, y, z). Box center; set Y to half-height to rest on ground.
    halfExtents : float * float * float - Half-dimensions (hx, hy, hz). (0.5,0.5,0.5)=1m cube. Reference: crate=(0.5,0.5,0.5), brick=(0.2,0.1,0.05), domino=(0.1,0.3,0.02).
    mass : float - Mass in kg. 0=static walls/floors. Reference: die=0.03, brick=3, crate=20.

Returns: SimulationCommand

Builds a box AddBody command.

id : string

Unique ID. Use nextId "box" for auto-generated.

pos : float * float * float

Position (x, y, z). Box center; set Y to half-height to rest on ground.

halfExtents : float * float * float

Half-dimensions (hx, hy, hz). (0.5,0.5,0.5)=1m cube. Reference: crate=(0.5,0.5,0.5), brick=(0.2,0.1,0.05), domino=(0.1,0.3,0.02).

mass : float

Mass in kg. 0=static walls/floors. Reference: die=0.03, brick=3, crate=20.

Returns: SimulationCommand

makeCapsuleCmd id pos radius length mass

Full Usage: makeCapsuleCmd id pos radius length mass

Parameters:
    id : string - Unique ID. Use nextId "capsule" for auto-generated.
    pos : float * float * float - Position (x, y, z). Capsule center.
    radius : float - Capsule radius in meters. Reference: limb=0.05, pipe=0.1, barrel=0.25.
    length : float - Cylinder portion length in meters (total = length + 2*radius). Reference: limb=0.3, pole=2.0.
    mass : float - Mass in kg. 0=static.

Returns: SimulationCommand

Builds a capsule AddBody command.

id : string

Unique ID. Use nextId "capsule" for auto-generated.

pos : float * float * float

Position (x, y, z). Capsule center.

radius : float

Capsule radius in meters. Reference: limb=0.05, pipe=0.1, barrel=0.25.

length : float

Cylinder portion length in meters (total = length + 2*radius). Reference: limb=0.3, pole=2.0.

mass : float

Mass in kg. 0=static.

Returns: SimulationCommand

makeColor r g b a

Full Usage: makeColor r g b a

Parameters:
    r : float
    g : float
    b : float
    a : float

Returns: Color

Creates a Color from RGBA (each 0.0–1.0). 1.0 alpha = opaque.

r : float
g : float
b : float
a : float
Returns: Color

makeCylinderCmd id pos radius length mass

Full Usage: makeCylinderCmd id pos radius length mass

Parameters:
    id : string - Unique ID. Use nextId "cylinder" for auto-generated.
    pos : float * float * float - Position (x, y, z). Cylinder center.
    radius : float - Cylinder radius in meters. Reference: coin=0.01, can=0.03, barrel=0.25.
    length : float - Cylinder height in meters. Reference: coin=0.002, can=0.12, barrel=0.9.
    mass : float - Mass in kg. 0=static.

Returns: SimulationCommand

Builds a cylinder AddBody command.

id : string

Unique ID. Use nextId "cylinder" for auto-generated.

pos : float * float * float

Position (x, y, z). Cylinder center.

radius : float

Cylinder radius in meters. Reference: coin=0.01, can=0.03, barrel=0.25.

length : float

Cylinder height in meters. Reference: coin=0.002, can=0.12, barrel=0.9.

mass : float

Mass in kg. 0=static.

Returns: SimulationCommand

makeDistanceLimitCmd id bodyA bodyB minDist maxDist

Full Usage: makeDistanceLimitCmd id bodyA bodyB minDist maxDist

Parameters:
    id : string - Unique constraint ID.
    bodyA : string - First body ID.
    bodyB : string - Second body ID.
    minDist : float - Minimum distance in meters.
    maxDist : float - Maximum distance in meters.

Returns: SimulationCommand

Builds a distance-limit constraint — keeps bodies within min/max distance.

id : string

Unique constraint ID.

bodyA : string

First body ID.

bodyB : string

Second body ID.

minDist : float

Minimum distance in meters.

maxDist : float

Maximum distance in meters.

Returns: SimulationCommand

makeDistanceSpringCmd id bodyA bodyB offsetA offsetB targetDistance

Full Usage: makeDistanceSpringCmd id bodyA bodyB offsetA offsetB targetDistance

Parameters:
    id : string
    bodyA : string
    bodyB : string
    offsetA : float * float * float
    offsetB : float * float * float
    targetDistance : float

Returns: SimulationCommand

Builds a distance-spring constraint — pulls bodies toward a target distance.

id : string
bodyA : string
bodyB : string
offsetA : float * float * float
offsetB : float * float * float
targetDistance : float
Returns: SimulationCommand

makeHingeCmd id bodyA bodyB axis offsetA offsetB

Full Usage: makeHingeCmd id bodyA bodyB axis offsetA offsetB

Parameters:
    id : string - Unique constraint ID.
    bodyA : string - First body ID.
    bodyB : string - Second body ID.
    axis : float * float * float - Hinge axis direction (x, y, z).
    offsetA : float * float * float - Local offset on body A.
    offsetB : float * float * float - Local offset on body B.

Returns: SimulationCommand

Builds a hinge constraint — rotation around a single axis.

id : string

Unique constraint ID.

bodyA : string

First body ID.

bodyB : string

Second body ID.

axis : float * float * float

Hinge axis direction (x, y, z).

offsetA : float * float * float

Local offset on body A.

offsetB : float * float * float

Local offset on body B.

Returns: SimulationCommand

makeImpulseCmd bodyId impulse

Full Usage: makeImpulseCmd bodyId impulse

Parameters:
    bodyId : string - Target body ID.
    impulse : float * float * float - Impulse (x, y, z) in N·s. Typical: (0,5,0) nudge, (0,50,0) launch, (10,0,0) push.

Returns: SimulationCommand

Builds an impulse command — instantaneous velocity change.

bodyId : string

Target body ID.

impulse : float * float * float

Impulse (x, y, z) in N·s. Typical: (0,5,0) nudge, (0,50,0) launch, (10,0,0) push.

Returns: SimulationCommand

makeLinearAxisMotorCmd id bodyA bodyB offsetA offsetB axis targetVelocity maxForce

Full Usage: makeLinearAxisMotorCmd id bodyA bodyB offsetA offsetB axis targetVelocity maxForce

Parameters:
    id : string
    bodyA : string
    bodyB : string
    offsetA : float * float * float
    offsetB : float * float * float
    axis : float * float * float
    targetVelocity : float
    maxForce : float

Returns: SimulationCommand

Builds a linear-axis-motor constraint — drives linear motion along an axis.

id : string
bodyA : string
bodyB : string
offsetA : float * float * float
offsetB : float * float * float
axis : float * float * float
targetVelocity : float
maxForce : float
Returns: SimulationCommand

makeMaterialProperties friction maxRecovery springFreq springDamping

Full Usage: makeMaterialProperties friction maxRecovery springFreq springDamping

Parameters:
    friction : float - Coulomb friction. 0=ice, 0.5=wood, 1.0=rubber.
    maxRecovery : float - Max recovery velocity m/s. Higher=bouncier.
    springFreq : float - Contact spring frequency Hz.
    springDamping : float - Contact spring damping ratio. 1.0=critical.

Returns: MaterialProperties

Creates MaterialProperties from physical parameters.

friction : float

Coulomb friction. 0=ice, 0.5=wood, 1.0=rubber.

maxRecovery : float

Max recovery velocity m/s. Higher=bouncier.

springFreq : float

Contact spring frequency Hz.

springDamping : float

Contact spring damping ratio. 1.0=critical.

Returns: MaterialProperties

makePointOnLineCmd id bodyA bodyB origin direction offset

Full Usage: makePointOnLineCmd id bodyA bodyB origin direction offset

Parameters:
    id : string
    bodyA : string
    bodyB : string
    origin : float * float * float
    direction : float * float * float
    offset : float * float * float

Returns: SimulationCommand

Builds a point-on-line constraint — constrains a point to slide along a line.

id : string
bodyA : string
bodyB : string
origin : float * float * float
direction : float * float * float
offset : float * float * float
Returns: SimulationCommand

makeRemoveConstraintCmd constraintId

Full Usage: makeRemoveConstraintCmd constraintId

Parameters:
    constraintId : string - ID of the constraint to remove.

Returns: SimulationCommand

Builds a remove-constraint command.

constraintId : string

ID of the constraint to remove.

Returns: SimulationCommand

makeSetBodyPoseCmd bodyId pos

Full Usage: makeSetBodyPoseCmd bodyId pos

Parameters:
    bodyId : string
    pos : float * float * float

Returns: SimulationCommand

Builds a SetBodyPose command to teleport/reposition a body.

bodyId : string
pos : float * float * float
Returns: SimulationCommand

makeSphereCmd id pos radius mass

Full Usage: makeSphereCmd id pos radius mass

Parameters:
    id : string - Unique ID. Use nextId "sphere" for auto-generated.
    pos : float * float * float - Position (x, y, z). Ground at Y=0.
    radius : float - Radius in meters. Reference: marble=0.01, bowling ball=0.11, beach ball=0.2, boulder=0.5.
    mass : float - Mass in kg. 0=static. Reference: marble=0.005, bowling ball=6.35, boulder=200.

Returns: SimulationCommand

Builds a sphere AddBody command.

id : string

Unique ID. Use nextId "sphere" for auto-generated.

pos : float * float * float

Position (x, y, z). Ground at Y=0.

radius : float

Radius in meters. Reference: marble=0.01, bowling ball=0.11, beach ball=0.2, boulder=0.5.

mass : float

Mass in kg. 0=static. Reference: marble=0.005, bowling ball=6.35, boulder=200.

Returns: SimulationCommand

makeSwingLimitCmd id bodyA bodyB axisA axisB maxAngle

Full Usage: makeSwingLimitCmd id bodyA bodyB axisA axisB maxAngle

Parameters:
    id : string
    bodyA : string
    bodyB : string
    axisA : float * float * float
    axisB : float * float * float
    maxAngle : float

Returns: SimulationCommand

Builds a swing-limit constraint — limits angle between two axes.

id : string
bodyA : string
bodyB : string
axisA : float * float * float
axisB : float * float * float
maxAngle : float
Returns: SimulationCommand

makeTorqueCmd bodyId torque

Full Usage: makeTorqueCmd bodyId torque

Parameters:
    bodyId : string - Target body ID.
    torque : float * float * float - Torque (x, y, z) in N·m. Axis = rotation direction, magnitude = strength. Typical: (0,5,0) gentle spin, (0,50,0) fast spin.

Returns: SimulationCommand

Builds a torque command — rotational force.

bodyId : string

Target body ID.

torque : float * float * float

Torque (x, y, z) in N·m. Axis = rotation direction, magnitude = strength. Typical: (0,5,0) gentle spin, (0,50,0) fast spin.

Returns: SimulationCommand

makeTwistLimitCmd id bodyA bodyB axisA axisB minAngle maxAngle

Full Usage: makeTwistLimitCmd id bodyA bodyB axisA axisB minAngle maxAngle

Parameters:
    id : string
    bodyA : string
    bodyB : string
    axisA : float * float * float
    axisB : float * float * float
    minAngle : float
    maxAngle : float

Returns: SimulationCommand

Builds a twist-limit constraint — limits rotation around an axis to an angle range.

id : string
bodyA : string
bodyB : string
axisA : float * float * float
axisB : float * float * float
minAngle : float
maxAngle : float
Returns: SimulationCommand

makeWeldCmd id bodyA bodyB

Full Usage: makeWeldCmd id bodyA bodyB

Parameters:
    id : string - Unique constraint ID.
    bodyA : string - First body ID.
    bodyB : string - Second body ID.

Returns: SimulationCommand

Builds a weld constraint — rigidly joins two bodies.

id : string

Unique constraint ID.

bodyA : string

First body ID.

bodyB : string

Second body ID.

Returns: SimulationCommand

nextId arg1

Full Usage: nextId arg1

Parameters:
    arg0 : string

Returns: string

Generates sequential body ID like "sphere-1". Each prefix has independent counter; resets on resetSimulation.

arg0 : string
Returns: string

ok arg1

Full Usage: ok arg1

Parameters:
Returns: 'a

Unwraps an Ok Result, throwing on Error. All PhysicsClient operations return Results — use this for scripting convenience.

arg0 : Result<'a, string>
Returns: 'a

overlapSphere session radius position

Full Usage: overlapSphere session radius position

Parameters:
    session : Session
    radius : float
    position : float * float * float

Returns: string list

Tests for overlapping bodies using a sphere. Returns overlapping body IDs.

session : Session
radius : float
position : float * float * float
Returns: string list

raycast session origin direction maxDistance

Full Usage: raycast session origin direction maxDistance

Parameters:
    session : Session - Active session.
    origin : float * float * float - Ray origin (x, y, z).
    direction : float * float * float - Ray direction (x, y, z).
    maxDistance : float - Maximum ray distance.

Returns: (string * (float * float * float) * (float * float * float) * float) list

Casts a ray and returns hit results as (bodyId, position, normal, distance) tuples.

session : Session

Active session.

origin : float * float * float

Ray origin (x, y, z).

direction : float * float * float

Ray direction (x, y, z).

maxDistance : float

Maximum ray distance.

Returns: (string * (float * float * float) * (float * float * float) * float) list

raycastAll session origin direction maxDistance

Full Usage: raycastAll session origin direction maxDistance

Parameters:
    session : Session
    origin : float * float * float
    direction : float * float * float
    maxDistance : float

Returns: (string * (float * float * float) * (float * float * float) * float) list

Casts a ray and returns all hits along the ray.

session : Session
origin : float * float * float
direction : float * float * float
maxDistance : float
Returns: (string * (float * float * float) * (float * float * float) * float) list

resetSimulation arg1

Full Usage: resetSimulation arg1

Parameters:

Resets simulation: pause, clear bodies, reset IDs, add ground plane, set gravity -9.81, wait 100ms.

arg0 : Session

runFor arg1 arg2

Full Usage: runFor arg1 arg2

Parameters:

Runs simulation for N seconds then pauses. 60 Hz timestep, so 3.0s = 180 steps.

arg0 : Session
arg1 : float

sleep arg1

Full Usage: sleep arg1

Parameters:
    arg0 : int

Pauses the current thread for the specified milliseconds.

arg0 : int

slipperyMaterial

Full Usage: slipperyMaterial

Returns: MaterialProperties

Slippery material: friction 0.01, recovery 2.0, spring 30 Hz / 1.0 damping.

Returns: MaterialProperties

stickyMaterial

Full Usage: stickyMaterial

Returns: MaterialProperties

Sticky material: friction 2.0, low recovery 0.5, spring 30 Hz / 1.0 damping.

Returns: MaterialProperties

sweepSphere session radius startPosition direction maxDistance

Full Usage: sweepSphere session radius startPosition direction maxDistance

Parameters:
    session : Session
    radius : float
    startPosition : float * float * float
    direction : float * float * float
    maxDistance : float

Returns: (string * (float * float * float) * (float * float * float) * float) option

Performs a sphere sweep cast. Returns Some (bodyId, position, normal, distance) or None.

session : Session
radius : float
startPosition : float * float * float
direction : float * float * float
maxDistance : float
Returns: (string * (float * float * float) * (float * float * float) * float) option

timed arg1 arg2

Full Usage: timed arg1 arg2

Parameters:
    arg0 : string
    arg1 : unit -> 'a

Returns: 'a

Times a function and prints elapsed duration. Output: [TIME] label: N ms.

arg0 : string
arg1 : unit -> 'a
Returns: 'a

toTuple arg1

Full Usage: toTuple arg1

Parameters:
Returns: float * float * float

Extracts Vec3 components as (X, Y, Z) tuple.

arg0 : Vec3
Returns: float * float * float

toVec3 arg1

Full Usage: toVec3 arg1

Parameters:
    arg0 : float * float * float

Returns: Vec3

Creates a protobuf Vec3 from (x, y, z). Y-up coordinate system; ground at Y=0.

arg0 : float * float * float
Returns: Vec3

Type something to start searching.