Path Constraints
Constrains a dynamic body to a built path in world space or relative to another body.
A PathConstraint keeps Body B on the curve owned by Body A. jolt_path_world() uses Jolt's fixed world as Body A; the body's initial constraint fraction is selected from the closest point on the path.
World-space path#
var cart = jolt_box_create_dynamic(-12, 0, 2, 1, 1, 1, { mass: 2 });
var rail = jolt_path_world(cart, track, {
rotation_mode: JOLT_PATH_ROTATION_FOLLOW,
friction_force: 8
});Body-relative path#
var rail = jolt_path(moving_base, cart, track, {
collision: false,
rotation_mode: JOLT_PATH_ROTATION_FREE
});Both bodies must be different, live managed bodies in the default world. The path is interpreted in Body A's local frame and moves with it.
Options#
| Option | Default | Meaning |
|---|---|---|
| rotation_mode | JOLT_PATH_ROTATION_FREE | How Body B may rotate relative to the path frame. |
| friction_force | 0 | Maximum non-negative force opposing motion along the path. |
| collision | true | Body-to-body constraints only: whether A and B may collide. |
| enabled | true | Initial constraint state. |
| motor_max_force | 100 | Maximum position-motor force. |
| motor_velocity | unset | Enables velocity motor when supplied. |
| motor_position | unset | Enables position motor when supplied. |
| motor_spring_frequency / damping | 2 / 1 | Position-motor spring settings. |
Rotation modes#
Runtime state#
rail.get_fraction()
rail.get_path_distance()
rail.get_speed()
rail.get_direction()
rail.get_impulse()
rail.get_rotation_mode()
rail.get_friction_force()get_speed() reports the relative velocity of the attached points projected onto the world-space path tangent. get_direction() returns that tangent.
Runtime friction#
if (!rail.set_friction_force(20)) {
show_debug_message(jolt_get_error_message());
}
var friction = rail.get_friction_force();set_friction_force(force) accepts a finite nonnegative force limit along the path and returns boolean success. Zero removes this friction. This is PathConstraint resistance, not a body's material coefficient. get_friction_force() can return zero both for a valid zero setting and on error, so check the error channel when necessary.
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.get_direction | JoltConstraint.get_direction() | Path only: unit world tangent {x, y, z}; undefined on error. |
| JoltConstraint.get_fraction | JoltConstraint.get_fraction() | Path only: normalized path parameter, 0 on error. Not a distance in metres. |
| JoltConstraint.get_friction_force | JoltConstraint.get_friction_force() | Path only: finite nonnegative friction in N. Setter Boolean, getter number or 0 on error. |
| JoltConstraint.get_impulse | JoltConstraint.get_impulse() | Latest solver impulse: Hinge motor/Cone in N·m·s; Distance/Slider motor/Path motor/Point/Pulley in N·s. 0 on error/unsupported type, not proof of zero load. |
| JoltConstraint.get_path_distance | JoltConstraint.get_path_distance() | Path only: distance along the path in m, 0 on error. |
| JoltConstraint.get_rotation_mode | JoltConstraint.get_rotation_mode() | Path only: JOLT_PATH_ROTATION_* mode. Setter Boolean, getter enum, FREE on error; inspect the error state. |
| JoltConstraint.get_speed | JoltConstraint.get_speed() | Path only: relative velocity along the tangent in m/s with respect to the path host; 0 on error. |
| JoltConstraint.set_friction_force | JoltConstraint.set_friction_force(force) | Path only: finite nonnegative friction in N. Setter Boolean, getter number or 0 on error. |
| JoltConstraint.set_rotation_mode | JoltConstraint.set_rotation_mode(mode) | Path only: JOLT_PATH_ROTATION_* mode. Setter Boolean, getter enum, FREE on error; inspect the error state. |