Sensors / Triggers
Detects overlaps and contacts without physical collision response.
A sensor remains a normal collision shape for broad-phase filtering, contact events, and raycasts, but Jolt does not use it to push or block other bodies.
High-Level API#
body.set_sensor(enabled)
body.is_sensor()Creation option#
var trigger_layer = jolt_layer_create("Triggers");
var trigger = jolt_box_create_dynamic(0, 0, 2, 4, 4, 4, {
sensor: true,
layer: trigger_layer
});
trigger.set_user_data({kind:"DamageZone", damage:10});The shared body option sensor defaults to false. set_sensor() changes the state at runtime and activates non-Static bodies. is_sensor() returns a Boolean; native errors are captured by the high-level wrapper.
What a sensor does#
| Feature | Sensor behaviour |
|---|---|
| Physical response | Disabled |
| ENTER / STAY / EXIT contacts | Generated when layer filtering permits the pair |
| Raycast hit | Included |
| Collision layers | Respected |
| Motion type | Dynamic, Static, and Kinematic shapes can be sensors |
Reading trigger events#
jolt_update();
var events = trigger.get_collisions();
for (var i = 0; i < array_length(events); ++i) {
var event = events[i];
if (event.type == JOLT_COLLISION_ENTER) {
show_debug_message("Entered trigger");
}
}Per-body events set sensor=true when either participant is a sensor. World events expose body_a_sensor and body_b_sensor separately.
Filtering and visualization#
A sensor pair still needs an enabled collision-layer combination. Raycasts do not automatically exclude sensors. Debug draw shows sensors only when JOLT_DEBUG_SENSORS is enabled; JOLT_DEBUG_SHAPES alone draws non-sensor bodies.
jolt_debug_enable(true);
jolt_debug_set(JOLT_DEBUG_SENSORS, true);
jolt_debug_draw();Low-Level / Advanced API#
Both functions use numeric world/body handles. The setter returns 1/0; the getter returns 1/0 and reports invalid handles through native error state.
Current project integrations#
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 |
|---|---|---|
| JoltBody.is_sensor | JoltBody.is_sensor() | Setter Boolean success, getter Boolean (also false on error). Sensor detects overlaps without ordinary contact response. |
| JoltBody.set_sensor | JoltBody.set_sensor(sensor) | Setter Boolean success, getter Boolean (also false on error). Sensor detects overlaps without ordinary contact response. |