Constraints
Slider Constraint
Restricts relative motion to one straight world-space axis while locking the other translations and all relative rotation.
Use jolt_slider() to connect two different managed bodies, or jolt_slider_world() to attach one managed body directly to Jolt's fixed world body. Both return the same managed JoltConstraint interface for limits, motors, state queries and cleanup.
Syntax#
jolt_slider(body_a, body_b, anchor_x, anchor_y, anchor_z, axis_x, axis_y, axis_z, options=undefined)
jolt_slider_world(body, anchor_x, anchor_y, anchor_z, axis_x, axis_y, axis_z, options=undefined)Arguments#
| Argument | Type | Description |
|---|---|---|
| body_a / body_b | JoltBody | Two different live bodies in the managed default world. |
| body | JoltBody | Single live body used by jolt_slider_world(). |
| anchor_x / anchor_y / anchor_z | Real | World-space shared attachment point. |
| axis_x / axis_y / axis_z | Real | Finite non-zero allowed translation axis, normalized internally. |
| options | Struct or undefined | Optional limits, collision, state, motor and spring settings. |
Options#
| Field | Default | Description |
|---|---|---|
| limits_min | -1000000 | Minimum position in world units; must be <= 0. |
| limits_max | 1000000 | Maximum position in world units; must be >= 0. |
| collision | true | Whether connected user bodies may collide; ignored by the world variant. |
| enabled | true | Initial solver state. |
| motor_max_force | 100 | Finite non-negative linear force limit. |
| spring_frequency | 2 | Position-motor spring frequency, applied at creation only when present. |
| spring_damping | 1 | Damping paired with spring_frequency. |
| motor_velocity | not set | Initial target in world units per second; selects velocity mode. |
| motor_position | not set | Initial target in world units; selects position mode. |
Methods#
| Method | Result | Slider behaviour |
|---|---|---|
| is_valid() | Boolean | Checks the managed wrapper and its native generational handle. |
| get_native_handle() | Real | Returns the opaque native handle, or 0 when invalid. |
| destroy() | Boolean | Idempotently releases only the constraint; connected bodies remain alive. |
| set_enabled(enabled) / get_enabled() | Boolean | Temporarily removes or restores solver participation without destroying the constraint. |
| set_collision_enabled(enabled) / get_collision_enabled() | Boolean | Controls collision for a body pair. World variants always report false. |
| set_limits(minimum, maximum) | Boolean | Updates finite linear limits containing zero. |
| get_limits() | Struct | Returns {minimum, maximum} in world units. |
| get_position() | Real | Current signed relative position along the axis. |
| set_motor_velocity(velocity) | Boolean | Selects velocity mode in units per second. |
| set_motor_position(position) | Boolean | Selects position mode in world units. |
| enable_motor(enabled) | Boolean | Turns the motor off or restores its previous mode. |
| set_motor_max_force(force) | Boolean | Updates the non-negative linear force limit. |
| get_motor_state() | Struct | Returns mode, targets, force limit and spring settings. |
| set_spring(frequency, damping) / get_spring() | Boolean / Struct | Controls the native position-motor spring. |
| get_impulse() | Real | Latest motor solver impulse, not force per second. |
Coordinates and motor rules#
- Positive position follows the supplied axis; reversing the axis reverses position and motor direction.
- The two perpendicular translations and all relative rotation are locked.
- Velocity and position setters select and enable their modes. The spring only affects position mode.
- If both creation targets are present, motor_position is applied last and becomes active.
Example: drawer#
var cabinet = jolt_box_create_static(4, 3.5, 2, 3.6, 3.8, 0.5);
var drawer = jolt_box_create_dynamic(4, 3.5, 2.75, 3, 2.6, 0.7, { mass: 4 });
var slider = jolt_slider(cabinet, drawer, 4, 3.5, 2.75, 0, -1, 0, {
limits_min: 0,
limits_max: 2,
collision: false
});Example: powered piston#
var slider = jolt_slider(frame, piston, 0, 0, 2, 1, 0, 0, {
limits_min: -1.5, limits_max: 1.5,
motor_max_force: 80,
spring_frequency: 3, spring_damping: 0.7,
motor_position: 1
});
slider.set_motor_velocity(-2);
slider.set_motor_position(1);
var position = slider.get_position();World variant#
var drawer = jolt_box_create_dynamic(0, 0, 1, 1.8, 2.5, 0.5, { mass: 3 });
var rail = jolt_slider_world(drawer, 0, 0, 1, 0, 1, 0, {
limits_min: -0.5,
limits_max: 0.5
});Errors and lifecycle#
- Body-to-body creators require two different live managed JoltBody values in the same managed default world.
- At least one connected body must be movable; native Jolt rejects an unsupported static-static pair.
- Constructors return a managed JoltConstraint on success or undefined after a validation/native creation failure.
- Destroying either attached body automatically destroys and invalidates the constraint before releasing that body.
- Read jolt_get_error() after a failed creator or method when the values may be untrusted.
- Anchor and axis components must be finite and the axis must not be zero length.
- Limits must be finite and satisfy minimum <= 0 <= maximum.
- Motor targets must be finite; force, frequency and damping must be finite and non-negative.
Verified operation contracts#
These contracts distinguish units, return values, errors and lifetime according to the current implementation. Check results: false, 0 and undefined can mean different things for different methods.
| Symbol / owner | Signature | Operation contract |
|---|---|---|
| jolt_slider | jolt_slider(body_a, body_b, anchor_x, anchor_y, anchor_z, axis_x, axis_y, axis_z, options = undefined) | Returns JoltConstraint/undefined, does not own bodies. Two distinct live same-world bodies; _world variant one Dynamic body and fixed world. Enabled defaults true; ordinary two-body collision defaults true unless specified otherwise below. Also check jolt_has_error after creation: some subsequent options can fail while returning the created constraint. World anchor/axis; limits_min/max default±1000000m, range includes0. Optional spring_frequency Hz and spring_damping default 1. |
| jolt_slider_world | jolt_slider_world(body, anchor_x, anchor_y, anchor_z, axis_x, axis_y, axis_z, options = undefined) | Returns JoltConstraint/undefined, does not own bodies. Two distinct live same-world bodies; _world variant one Dynamic body and fixed world. Enabled defaults true; ordinary two-body collision defaults true unless specified otherwise below. Also check jolt_has_error after creation: some subsequent options can fail while returning the created constraint. World anchor/axis; limits_min/max default±1000000m, range includes0. Optional spring_frequency Hz and spring_damping default 1. |