Paths

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#

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

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

OptionDefaultMeaning
rotation_modeJOLT_PATH_ROTATION_FREEHow Body B may rotate relative to the path frame.
friction_force0Maximum non-negative force opposing motion along the path.
collisiontrueBody-to-body constraints only: whether A and B may collide.
enabledtrueInitial constraint state.
motor_max_force100Maximum position-motor force.
motor_velocityunsetEnables velocity motor when supplied.
motor_positionunsetEnables position motor when supplied.
motor_spring_frequency / damping2 / 1Position-motor spring settings.

Rotation modes#

Runtime state#

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

GML
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 / ownerSignatureOperation contract
JoltConstraint.get_directionJoltConstraint.get_direction()Path only: unit world tangent {x, y, z}; undefined on error.
JoltConstraint.get_fractionJoltConstraint.get_fraction()Path only: normalized path parameter, 0 on error. Not a distance in metres.
JoltConstraint.get_friction_forceJoltConstraint.get_friction_force()Path only: finite nonnegative friction in N. Setter Boolean, getter number or 0 on error.
JoltConstraint.get_impulseJoltConstraint.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_distanceJoltConstraint.get_path_distance()Path only: distance along the path in m, 0 on error.
JoltConstraint.get_rotation_modeJoltConstraint.get_rotation_mode()Path only: JOLT_PATH_ROTATION_* mode. Setter Boolean, getter enum, FREE on error; inspect the error state.
JoltConstraint.get_speedJoltConstraint.get_speed()Path only: relative velocity along the tangent in m/s with respect to the path host; 0 on error.
JoltConstraint.set_friction_forceJoltConstraint.set_friction_force(force)Path only: finite nonnegative friction in N. Setter Boolean, getter number or 0 on error.
JoltConstraint.set_rotation_modeJoltConstraint.set_rotation_mode(mode)Path only: JOLT_PATH_ROTATION_* mode. Setter Boolean, getter enum, FREE on error; inspect the error state.