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#

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#

ArgumentTypeDescription
body_a / body_bJoltBodyTwo different live bodies in the managed default world.
bodyJoltBodySingle live body used by jolt_slider_world().
anchor_x / anchor_y / anchor_zRealWorld-space shared attachment point.
axis_x / axis_y / axis_zRealFinite non-zero allowed translation axis, normalized internally.
optionsStruct or undefinedOptional limits, collision, state, motor and spring settings.

Options#

FieldDefaultDescription
limits_min-1000000Minimum position in world units; must be <= 0.
limits_max1000000Maximum position in world units; must be >= 0.
collisiontrueWhether connected user bodies may collide; ignored by the world variant.
enabledtrueInitial solver state.
motor_max_force100Finite non-negative linear force limit.
spring_frequency2Position-motor spring frequency, applied at creation only when present.
spring_damping1Damping paired with spring_frequency.
motor_velocitynot setInitial target in world units per second; selects velocity mode.
motor_positionnot setInitial target in world units; selects position mode.

Methods#

MethodResultSlider behaviour
is_valid()BooleanChecks the managed wrapper and its native generational handle.
get_native_handle()RealReturns the opaque native handle, or 0 when invalid.
destroy()BooleanIdempotently releases only the constraint; connected bodies remain alive.
set_enabled(enabled) / get_enabled()BooleanTemporarily removes or restores solver participation without destroying the constraint.
set_collision_enabled(enabled) / get_collision_enabled()BooleanControls collision for a body pair. World variants always report false.
set_limits(minimum, maximum)BooleanUpdates finite linear limits containing zero.
get_limits()StructReturns {minimum, maximum} in world units.
get_position()RealCurrent signed relative position along the axis.
set_motor_velocity(velocity)BooleanSelects velocity mode in units per second.
set_motor_position(position)BooleanSelects position mode in world units.
enable_motor(enabled)BooleanTurns the motor off or restores its previous mode.
set_motor_max_force(force)BooleanUpdates the non-negative linear force limit.
get_motor_state()StructReturns mode, targets, force limit and spring settings.
set_spring(frequency, damping) / get_spring()Boolean / StructControls the native position-motor spring.
get_impulse()RealLatest 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#

GML
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#

GML
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#

GML
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 / ownerSignatureOperation contract
jolt_sliderjolt_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_worldjolt_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.