Header menu logo PhysicsSandbox

ConstraintBuilders Module

Factory functions for constructing constraint-related SimulationCommand messages from simple F# values.

These builders hide the nested proto message hierarchy (ConstraintType → AddConstraint → SimulationCommand). Use batchAdd to send the resulting commands. Constraint IDs can be generated with nextId "constraint".

Functions and values

Function or value Description

makeAngularMotorCmd id bodyA bodyB targetVelocity maxForce

Full Usage: makeAngularMotorCmd id bodyA bodyB targetVelocity maxForce

Parameters:
    id : string - Unique constraint ID.
    bodyA : string - ID of the first body.
    bodyB : string - ID of the second body.
    targetVelocity : float * float * float - Target angular velocity (x, y, z) in rad/s.
    maxForce : float - Maximum force the motor can apply.

Returns: SimulationCommand

Builds an AddConstraint command for an angular motor — drives rotation around axes.

id : string

Unique constraint ID.

bodyA : string

ID of the first body.

bodyB : string

ID of the second body.

targetVelocity : float * float * float

Target angular velocity (x, y, z) in rad/s.

maxForce : float

Maximum force the motor can apply.

Returns: SimulationCommand

makeBallSocketCmd id bodyA bodyB offsetA offsetB

Full Usage: makeBallSocketCmd id bodyA bodyB offsetA offsetB

Parameters:
    id : string - Unique constraint ID. Use nextId "constraint" for auto-generated IDs.
    bodyA : string - ID of the first body.
    bodyB : string - ID of the second body.
    offsetA : float * float * float - Local-space offset on body A (x, y, z) where the socket attaches. Example: (0.0, 0.5, 0.0) = top of a 1m-tall body.
    offsetB : float * float * float - Local-space offset on body B (x, y, z) where the socket attaches.

Returns: SimulationCommand A SimulationCommand ready for batchAdd.

Builds an AddConstraint command for a ball-socket joint — allows free rotation around the anchor point.

id : string

Unique constraint ID. Use nextId "constraint" for auto-generated IDs.

bodyA : string

ID of the first body.

bodyB : string

ID of the second body.

offsetA : float * float * float

Local-space offset on body A (x, y, z) where the socket attaches. Example: (0.0, 0.5, 0.0) = top of a 1m-tall body.

offsetB : float * float * float

Local-space offset on body B (x, y, z) where the socket attaches.

Returns: SimulationCommand

A SimulationCommand ready for batchAdd.

Example

 let joint = makeBallSocketCmd "joint-1" "arm" "forearm" (0.0, -0.5, 0.0) (0.0, 0.5, 0.0)
 batchAdd session [joint]
val joint: obj

makeDistanceLimitCmd id bodyA bodyB minDist maxDist

Full Usage: makeDistanceLimitCmd id bodyA bodyB minDist maxDist

Parameters:
    id : string - Unique constraint ID.
    bodyA : string - ID of the first body.
    bodyB : string - ID of the second body.
    minDist : float - Minimum allowed distance in meters. Use 0 for no minimum.
    maxDist : float - Maximum allowed distance in meters. Typical: 1.0–10.0 for chain links.

Returns: SimulationCommand A SimulationCommand ready for batchAdd.

Builds an AddConstraint command for a distance limit — keeps two bodies within a distance range.

id : string

Unique constraint ID.

bodyA : string

ID of the first body.

bodyB : string

ID of the second body.

minDist : float

Minimum allowed distance in meters. Use 0 for no minimum.

maxDist : float

Maximum allowed distance in meters. Typical: 1.0–10.0 for chain links.

Returns: SimulationCommand

A SimulationCommand ready for batchAdd.

Example

 let chain = makeDistanceLimitCmd "chain-1" "link-1" "link-2" 0.5 1.5
 batchAdd session [chain]
val chain: obj

makeDistanceSpringCmd id bodyA bodyB offsetA offsetB targetDistance

Full Usage: makeDistanceSpringCmd id bodyA bodyB offsetA offsetB targetDistance

Parameters:
    id : string - Unique constraint ID.
    bodyA : string - ID of the first body.
    bodyB : string - ID of the second body.
    offsetA : float * float * float - Local-space offset on body A (x, y, z).
    offsetB : float * float * float - Local-space offset on body B (x, y, z).
    targetDistance : float - Target distance in meters that the spring pulls toward.

Returns: SimulationCommand

Builds an AddConstraint command for a distance spring — pulls two bodies toward a target distance.

id : string

Unique constraint ID.

bodyA : string

ID of the first body.

bodyB : string

ID of the second body.

offsetA : float * float * float

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

offsetB : float * float * float

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

targetDistance : float

Target distance in meters that the spring pulls toward.

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 - ID of the first body.
    bodyB : string - ID of the second body.
    axis : float * float * float - Hinge axis direction (x, y, z). Example: (0.0, 1.0, 0.0) for vertical hinge, (1.0, 0.0, 0.0) for horizontal hinge along X.
    offsetA : float * float * float - Local-space attachment offset on body A.
    offsetB : float * float * float - Local-space attachment offset on body B.

Returns: SimulationCommand A SimulationCommand ready for batchAdd.

Builds an AddConstraint command for a hinge joint — allows rotation around a single axis.

id : string

Unique constraint ID.

bodyA : string

ID of the first body.

bodyB : string

ID of the second body.

axis : float * float * float

Hinge axis direction (x, y, z). Example: (0.0, 1.0, 0.0) for vertical hinge, (1.0, 0.0, 0.0) for horizontal hinge along X.

offsetA : float * float * float

Local-space attachment offset on body A.

offsetB : float * float * float

Local-space attachment offset on body B.

Returns: SimulationCommand

A SimulationCommand ready for batchAdd.

Example

 let hinge = makeHingeCmd "hinge-1" "door" "frame" (0.0, 1.0, 0.0) (-0.5, 0.0, 0.0) (0.5, 0.0, 0.0)
 batchAdd session [hinge]
val hinge: obj

makeLinearAxisMotorCmd id bodyA bodyB offsetA offsetB axis targetVelocity maxForce

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

Parameters:
    id : string - Unique constraint ID.
    bodyA : string - ID of the first body.
    bodyB : string - ID of the second body.
    offsetA : float * float * float - Local-space offset on body A (x, y, z).
    offsetB : float * float * float - Local-space offset on body B (x, y, z).
    axis : float * float * float - Local axis direction (x, y, z) for the motor.
    targetVelocity : float - Target velocity along the axis in m/s.
    maxForce : float - Maximum force the motor can apply.

Returns: SimulationCommand

Builds an AddConstraint command for a linear axis motor — drives linear motion along an axis.

id : string

Unique constraint ID.

bodyA : string

ID of the first body.

bodyB : string

ID of the second body.

offsetA : float * float * float

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

offsetB : float * float * float

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

axis : float * float * float

Local axis direction (x, y, z) for the motor.

targetVelocity : float

Target velocity along the axis in m/s.

maxForce : float

Maximum force the motor can apply.

Returns: SimulationCommand

makePointOnLineCmd id bodyA bodyB origin direction offset

Full Usage: makePointOnLineCmd id bodyA bodyB origin direction offset

Parameters:
    id : string - Unique constraint ID.
    bodyA : string - ID of the first body.
    bodyB : string - ID of the second body.
    origin : float * float * float - Local origin of the line on body A (x, y, z).
    direction : float * float * float - Local direction of the line (x, y, z).
    offset : float * float * float - Local offset on body B (x, y, z).

Returns: SimulationCommand

Builds an AddConstraint command for a point-on-line constraint — constrains a point to slide along a line.

id : string

Unique constraint ID.

bodyA : string

ID of the first body.

bodyB : string

ID of the second body.

origin : float * float * float

Local origin of the line on body A (x, y, z).

direction : float * float * float

Local direction of the line (x, y, z).

offset : float * float * float

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

Returns: SimulationCommand

makeRemoveConstraintCmd constraintId

Full Usage: makeRemoveConstraintCmd constraintId

Parameters:
    constraintId : string - The ID of the constraint to remove. Must match a previously added constraint.

Returns: SimulationCommand A SimulationCommand ready for batchAdd.

Builds a RemoveConstraint command to delete an existing constraint.

constraintId : string

The ID of the constraint to remove. Must match a previously added constraint.

Returns: SimulationCommand

A SimulationCommand ready for batchAdd.

Example

 let remove = makeRemoveConstraintCmd "joint-1"
 batchAdd session [remove]
val remove: obj

makeSwingLimitCmd id bodyA bodyB axisA axisB maxAngle

Full Usage: makeSwingLimitCmd id bodyA bodyB axisA axisB maxAngle

Parameters:
    id : string - Unique constraint ID.
    bodyA : string - ID of the first body.
    bodyB : string - ID of the second body.
    axisA : float * float * float - Local axis on body A (x, y, z).
    axisB : float * float * float - Local axis on body B (x, y, z).
    maxAngle : float - Maximum swing angle in radians.

Returns: SimulationCommand

Builds an AddConstraint command for a swing limit — limits the angle between two axes.

id : string

Unique constraint ID.

bodyA : string

ID of the first body.

bodyB : string

ID of the second body.

axisA : float * float * float

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

axisB : float * float * float

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

maxAngle : float

Maximum swing angle in radians.

Returns: SimulationCommand

makeTwistLimitCmd id bodyA bodyB axisA axisB minAngle maxAngle

Full Usage: makeTwistLimitCmd id bodyA bodyB axisA axisB minAngle maxAngle

Parameters:
    id : string - Unique constraint ID.
    bodyA : string - ID of the first body.
    bodyB : string - ID of the second body.
    axisA : float * float * float - Local axis on body A (x, y, z).
    axisB : float * float * float - Local axis on body B (x, y, z).
    minAngle : float - Minimum twist angle in radians.
    maxAngle : float - Maximum twist angle in radians.

Returns: SimulationCommand

Builds an AddConstraint command for a twist limit — limits rotation around an axis to an angle range.

id : string

Unique constraint ID.

bodyA : string

ID of the first body.

bodyB : string

ID of the second body.

axisA : float * float * float

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

axisB : float * float * float

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

minAngle : float

Minimum twist angle in radians.

maxAngle : float

Maximum twist angle in radians.

Returns: SimulationCommand

makeWeldCmd id bodyA bodyB

Full Usage: makeWeldCmd id bodyA bodyB

Parameters:
    id : string - Unique constraint ID.
    bodyA : string - ID of the first body.
    bodyB : string - ID of the second body. The bodies are welded at their current relative position and orientation.

Returns: SimulationCommand A SimulationCommand ready for batchAdd.

Builds an AddConstraint command for a weld joint — rigidly fixes two bodies together.

id : string

Unique constraint ID.

bodyA : string

ID of the first body.

bodyB : string

ID of the second body. The bodies are welded at their current relative position and orientation.

Returns: SimulationCommand

A SimulationCommand ready for batchAdd.

Example

 let weld = makeWeldCmd "weld-1" "plate-1" "plate-2"
 batchAdd session [weld]
val weld: obj

Type something to start searching.