Motors and Springs
Drives supported degrees of freedom with bounded force or torque and softens positional correction with native springs.
Motors are solver targets, not direct teleportation. Their effective motion depends on mass, inertia, contacts, limits, fixed timestep and the configured force or torque budget. Hinge motor torque is bounded by set_motor_max_torque().
Motor support#
| Type | Targets | Strength limit | Spring |
|---|---|---|---|
| Hinge | Velocity in rad/s; position in degrees | set_motor_max_torque() | set_motor_spring() for position mode |
| Slider | Velocity in units/s; position in world units | set_motor_max_force() | set_spring() for position mode |
| SwingTwist | Separate swing/twist velocity and position | Separate maximum torques | Separate swing/twist motor springs |
| SixDOF | Translation vectors, angular velocity and target orientation | Per-axis force or torque | Per-axis motor springs |
| Path | Velocity and distance-along-path position | set_motor_max_force() | set_motor_spring() |
Hinge and Slider modes#
- set_motor_velocity() selects and enables velocity mode.
- set_motor_position() selects and enables position mode.
- enable_motor(false) turns the motor off without forgetting its last mode; true restores it.
- A zero force/torque limit prevents useful drive while leaving the mode selected.
- Position-mode spring frequency controls stiffness; damping suppresses oscillation.
Hinge example#
hinge.set_motor_max_torque(35);
hinge.set_motor_spring(3, 0.8);
hinge.set_motor_position(90); // degrees
// Switch to velocity mode later.
hinge.set_motor_velocity(4); // radians per secondSlider example#
slider.set_motor_max_force(80);
slider.set_spring(3, 0.7);
slider.set_motor_position(1.25); // world units
var state = slider.get_motor_state();SwingTwist and SixDOF#
SwingTwist has independent native motors for swing and twist. SixDOF exposes JOLT_MOTOR_OFF, JOLT_MOTOR_VELOCITY, JOLT_MOTOR_POSITION and JOLT_MOTOR_POSITION_VELOCITY per axis, with shared vector/orientation targets and individual force/torque limits.
Springs and fixed timestep#
- Distance set_spring() softens correction toward its permitted length range and does not require a motor.
- Hinge, Slider, SwingTwist, SixDOF and Path springs belong to position motors.
- SixDOF limit springs are separate from motor springs and support translation axes only in Jolt 5.6.
- Very high frequency, low damping, large mass ratios or a large fixed_dt can destabilize or under-resolve the mechanism.
- Tune with the production fixed_dt and realistic body masses rather than compensating with unbounded strength.
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 |
|---|---|---|
| JoltConstraint.enable_motor | JoltConstraint.enable_motor(enabled) | Hinge/Slider/Path: Boolean success. False disables the motor, true restores the last mode, default enabling mode VELOCITY. |
| JoltConstraint.get_motor_state | JoltConstraint.get_motor_state() | Hinge/Slider/Path struct {enabled, mode, target_velocity, target_position, spring_frequency, spring_damping, max_torque|max_force}, undefined on error. Hinge velocity rad/s, position °, max_torque N·m; Slider/Path velocity m/s, position m, max_force N. |
| JoltConstraint.set_motor_max_force | JoltConstraint.set_motor_max_force(force) | Slider/Path only: finite nonnegative limit in N, Boolean. |
| JoltConstraint.set_motor_max_torque | JoltConstraint.set_motor_max_torque(torque) | Hinge only: finite nonnegative limit in N·m, Boolean. |
| JoltConstraint.set_motor_position | JoltConstraint.set_motor_position(position) | Hinge: finite angle in degrees; Slider: displacement in m; Path: distance along the path in m. Boolean; enables POSITION motor. |
| JoltConstraint.set_motor_spring | JoltConstraint.set_motor_spring(frequency, damping) | Hinge/Path only: finite frequency ≥0 Hz and damping ≥0 (ratio); Boolean. Use set_spring for Slider. |
| JoltConstraint.set_motor_velocity | JoltConstraint.set_motor_velocity(velocity) | Hinge: finite velocity in rad/s; Slider/Path: m/s. Boolean; sets target and enables VELOCITY motor. Hinge does not use degrees/s here. |