Constraints
Cone Constraint
Keeps a shared anchor together and limits swing to a circular cone while leaving twist around the axis free.
Cone is useful for pendants, simple ball joints and links that may tilt by a maximum angle but do not need twist limits. For elliptical swing, twist limits or angular motors, use SwingTwist instead.
Syntax#
jolt_cone(body_a, body_b, anchor_x, anchor_y, anchor_z, axis_x, axis_y, axis_z, max_angle, options=undefined)
jolt_cone_world(body, anchor_x, anchor_y, anchor_z, axis_x, axis_y, axis_z, max_angle, options=undefined)Arguments and options#
| Name | Default | Description |
|---|---|---|
| body_a / body_b | required | Connected managed bodies. |
| body | required | Single body for the world variant. |
| anchor_x / anchor_y / anchor_z | required | Shared world-space pivot. |
| axis_x / axis_y / axis_z | required | Finite non-zero reference direction, normalized internally. |
| max_angle | required | Swing half-angle from 0 to 180 degrees. |
| collision | true | Body-to-body collision state; ignored by the world variant. |
| enabled | true | Initial solver state. |
Angular behaviour#
- The current axis may swing away from the reference axis by at most max_angle.
- Relative twist around that axis remains unconstrained.
- A limit of 0 degrees locks swing; 180 degrees is effectively free swing.
- The public API uses degrees and converts to Jolt radians internally.
Methods#
| Method | Result | Cone 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_limit(angle) | Boolean | Sets the 0..180 degree swing half-angle. |
| get_limit() | Real | Returns the configured maximum swing in degrees. |
| get_angle() | Real | Returns the current swing angle in degrees. |
| get_impulse() | Real | Returns the latest positional/angular solver impulse summary. |
Example: hanging lamp#
var lamp = jolt_box_create_dynamic(0, 0, 3.5, 0.7, 0.7, 1, { mass: 3 });
var joint = jolt_cone_world(
lamp,
0, 0, 4,
0, 0, -1,
35
);Body-to-body example#
var joint = jolt_cone(upper, lower, 0, 0, 4.5, 0, 0, -1, 45, {
collision: false
});
joint.set_limit(30);
var swing = joint.get_angle();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 have non-zero length.
- max_angle and runtime limits must remain between 0 and 180 degrees.
- Cone exposes no motor or spring. Use SwingTwist or SixDOF for powered angular control.
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_cone | jolt_cone(body_a, body_b, anchor_x, anchor_y, anchor_z, axis_x, axis_y, axis_z, max_angle, 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 and max_angle degrees0..180. |
| jolt_cone_world | jolt_cone_world(body, anchor_x, anchor_y, anchor_z, axis_x, axis_y, axis_z, max_angle, 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 and max_angle degrees0..180. |
| JoltConstraint.set_rotation | JoltConstraint.set_rotation(angle) | Hinge only: finite reference angle in degrees; Boolean. Changes the reference frame, does not teleport the body. |