Skip to content

Collisions and triggers

Updated

Most game logic starts with “when this touches that”: a ball crosses the goal line, the player steps on a pressure plate, a crate smashes into the floor hard enough to break. Physics reports these moments as collision events. This page explains the four events, the data they carry, how to receive them in a script, and how to build invisible trigger volumes with sensor colliders.

  • You have entities with colliders, as described in Rigid bodies and colliders.
  • You know how a script listens to a signal with on(signal, callback) and compares event.eventType with EventType constants. See Scripting and Events and signals.
  • Physics, and therefore every event on this page, runs in play only.

Two colliders that meet do one of two things:

  • Collide. They push each other apart: a solid contact. A ball lands on the floor; a crate hits a wall.
  • Intersect. They pass through each other and only report the overlap. This happens when either collider is a sensor, or when their physics layers are set to intersect.

Each kind has an event when it begins and one when it ends:

eventType Constant When
PhysicsCollider::collision-enter EventType.PhysicsCollider.CollisionEnter A solid contact began.
PhysicsCollider::collision-exit EventType.PhysicsCollider.CollisionExit It ended.
PhysicsCollider::intersection-enter EventType.PhysicsCollider.IntersectionEnter An overlap began: either collider is a sensor, or the two layers intersect.
PhysicsCollider::intersection-exit EventType.PhysicsCollider.IntersectionExit It ended.

Each touching pair sends one enter and then the exit of the same kind, also when the other collider is removed while touching. Two layers set to ignore each other send nothing at all.

Components never call your script directly. A collider hands its events to every Signal Emitter on its entity, and the Signal Emitter puts them on the event bus under its signal. Your script listens to that signal.

  1. Add a Signal Emitter to the entity whose contacts you care about, and give it a signal, for example goal.
  2. In a script, call on('goal', (event) => { … }).
  3. Inside, check event.eventType against an EventType.PhysicsCollider constant.

Every event the listener receives has this shape:

Field Description
event.entityId The entity carrying the Signal Emitter: the one whose collider was touched.
event.eventType One of the four strings above.
event.data The details, listed below.

event.data carries:

Field Type Description
otherEntityId string, optional The other entity, when the other collider belongs to one. Absent for stray world geometry.
contact { x, y, z }, optional The world-space contact point. Only on collision-enter, and only when a contact point was produced.
sceneId string, optional The scene this entity belongs to.
otherSceneId string, optional The scene the other entity belongs to. Entity ids can repeat across loaded scenes, so use it when several scenes are loaded.
colliderHandle number, optional The live handle of this collider.
otherColliderHandle number, optional The live handle of the other collider. With colliderHandle, it tells apart the different shapes of a compound body.

A Signal Emitter forwards every event of its entity by default. Its eventFilter prop, a list of eventType strings, lets only those through. For example, a Signal Emitter with signal set to crate/hit and eventFilter set to PhysicsCollider::collision-enter sends only the start of solid contacts, so the script does not even need to check the type. An entity may carry several Signal Emitters with different signals and filters.

The project’s physics settings can also switch off collision reports or intersection reports for the whole app. Both are on by default.

A sensor is a collider with its sensor prop on. It reports overlaps but never pushes anything, and nothing pushes it. Sensors are how you make zones:

  • a goal line, a finish line, a checkpoint;
  • a pressure plate or a doorway that opens a door;
  • a “kill zone” under the level that respawns whatever falls in;
  • a room that changes the music when the player enters.

To build a trigger volume:

  1. Add a Group where the zone should be.
  2. Add a Box Collider to it with a size covering the zone, and turn on sensor.
  3. Add a Signal Emitter with a signal, such as checkpoint.
  4. Listen for IntersectionEnter and IntersectionExit in a script.

A group has no visible mesh, so the zone is invisible in play. Without a Rigid Body the group gets a fixed body, which is what a trigger needs.

A sensor never blocks rays: PhysicsRaycaster passes through sensors. A sensor on a fixed body also sees kinematic bodies, such as a Character Controller walking through it.

A Character Controller’s capsule sends collider events too, on a Signal Emitter on the character’s entity:

  • intersection-enter and intersection-exit for the triggers it walks through;
  • collision-enter and collision-exit for what it rests on, such as the floor.

A wall or a box the character walks into is not a contact: the capsule slides along it and stops just short of it, so no event is sent. To detect what a character bumps into, put a slightly larger sensor around it, or test ahead of it with a ray.

Events tell you when something happens. When you need to ask at a given moment (“is there ground under me?”, “can the guard see the player?”), cast a ray against the colliders with PhysicsRaycaster. It tests colliders only, never hits sensors, and its collisionLayers option limits it to some physics layers. See Picking and raycasts.

A sensor box behind the goal line reports the ball crossing it.

Goal.jx
#pragma lifecycle(startup)
let score = 0;
function startup() {
on('goal', (event) => {
if (event.eventType !== EventType.PhysicsCollider.IntersectionEnter) return;
const other = findEntity(event.data.otherEntityId || '');
if (!other || other.name !== 'Ball') return;
score += 1;
log('Goal! Score:', score);
emit('score/changed', { score });
});
}
  • The goal’s collider is a sensor, so the ball passes through it and the goal reports an intersection, not a collision.
  • otherEntityId is the entity that entered. findEntity(… || '') handles the case where it is absent.
  • Checking other.name ignores anything else that wanders in, such as a player.
  • emit passes the new score to other scripts, for example one that updates a UI label.

When the player walks through a checkpoint, it becomes the new respawn point.

Checkpoint.jx
#pragma lifecycle(startup)
let player;
let respawn = null;
// Each checkpoint is a group with a sensor Box Collider and a Signal Emitter with the signal 'checkpoint'.
// The Player entity has a Character Controller.
function startup() {
player = findEntity('Player');
on('checkpoint', (event) => {
if (event.eventType !== EventType.PhysicsCollider.IntersectionEnter) return;
if (event.data.otherEntityId !== player.entityId) return;
const checkpoint = findEntity(event.entityId);
respawn = checkpoint.position.clone();
log('Checkpoint reached:', checkpoint.name);
});
on('player/died', () => {
if (respawn) player.getComponent(CharacterControllerComponent).teleport(respawn);
});
}
  • Every checkpoint uses the same signal, checkpoint; event.entityId says which one fired.
  • The fixed sensor sees the Character Controller’s kinematic capsule, so walking through it sends IntersectionEnter.
  • Comparing otherEntityId with player.entityId ignores crates or other characters.
  • On player/died, emitted by another script, the Character Controller’s teleport puts the player on the last checkpoint.

A crate shows sparks at the contact point when it hits something fast enough.

ImpactSparks.jx
#pragma lifecycle(startup, update)
const HARD_HIT = 4; // metres per second
let body;
let lastSpeed = 0;
// On a dynamic Crate with a Rigid Body, a Box Collider and a Signal Emitter with the signal 'crate'.
// A disabled entity named 'Sparks' in the scene is the effect to copy.
function startup() {
body = self.parent.getComponent(PhysicsRigidBodyComponent);
on('crate', (event) => {
if (event.entityId !== self.parent.entityId) return;
if (event.eventType !== EventType.PhysicsCollider.CollisionEnter) return;
if (lastSpeed < HARD_HIT || !event.data.contact) return;
const sparks = spawn('Sparks', { position: event.data.contact, enabled: true });
delay(() => destroy(sparks), 1000);
});
}
function update() {
const v = body.linearVelocity();
lastSpeed = Math.hypot(v.x, v.y, v.z);
}
  • update keeps the crate’s speed from the previous frame. At the moment of impact the body has already slowed, so the speed just before is the one that matters.
  • If several crates share the signal crate, the entityId check keeps only this crate’s own events.
  • event.data.contact is the world point where the contact began. It is only on collision-enter, and can be missing, hence the check.
  • spawn copies the Sparks entity at that point; delay destroys the copy a second later.

4. A pressure plate that counts what stands on it

Section titled “4. A pressure plate that counts what stands on it”

A door stays open while at least one body is on the plate.

PressurePlate.jx
#pragma lifecycle(startup)
const onPlate = new Set();
// The Plate is a group with a thin sensor Box Collider and a Signal Emitter with the signal 'plate'.
function startup() {
on('plate', (event) => {
const id = event.data.otherEntityId;
if (!id) return;
const before = onPlate.size;
if (event.eventType === EventType.PhysicsCollider.IntersectionEnter) onPlate.add(id);
if (event.eventType === EventType.PhysicsCollider.IntersectionExit) onPlate.delete(id);
if (before === 0 && onPlate.size > 0) emit('door/open');
if (before > 0 && onPlate.size === 0) emit('door/close');
});
}
  • A Set holds the ids of the bodies on the plate, so the same body never counts twice.
  • Every enter is followed by an exit of the same kind, so the set always returns to empty.
  • The door is told only when the count crosses zero, not on every step on or off.
  • Another script, or an Enable on Signal component, reacts to door/open and door/close.

A ball may jump only while it rests on something. Counting its solid contacts tells the script whether it is grounded.

GroundedJump.jx
#pragma lifecycle(startup, update)
let body;
let contacts = 0;
// On a dynamic Ball with a Rigid Body, a Sphere Collider and a Signal Emitter with the signal 'ball'.
function startup() {
body = self.parent.getComponent(PhysicsRigidBodyComponent);
on('ball', (event) => {
if (event.entityId !== self.parent.entityId) return;
if (event.eventType === EventType.PhysicsCollider.CollisionEnter) contacts += 1;
if (event.eventType === EventType.PhysicsCollider.CollisionExit) contacts = Math.max(0, contacts - 1);
});
}
function update() {
if (contacts > 0 && Input.keyboard.isKeyReleased(Key.Space)) {
body.applyImpulse({ x: 0, y: 3, z: 0 });
}
}
  • Every solid contact that begins is followed by its exit, so contacts is the number of things the ball touches right now.
  • Math.max keeps the count from going below zero if the script starts while the ball is already touching something.
  • A wall the ball touches also counts. To accept only the floor, also check event.data.otherEntityId, or cast a short PhysicsRaycaster ray downwards instead.
  • On a compound body, each of its shapes reports its own contacts. event.data.colliderHandle and otherColliderHandle tell the pairs apart when you need to.
  • No Signal Emitter, or no signal. Without an enabled Signal Emitter with a signal when the body is built, nothing is sent.
  • Adding the Signal Emitter later. Events are wired when the body is built. Add the emitter in the editor, not halfway through play.
  • Listening for collisions on a sensor. Sensors only ever send intersection-enter and intersection-exit.
  • Expecting wall bumps from a Character Controller. Its capsule slides along walls and sends no contact for them.
  • Reading contact on other events. It exists only on collision-enter, and not always.
  • Using the same signal for several entities without checking. Check event.entityId to know which entity sent the event.
  • Two layers set to ignore. Colliders on ignoring layers never meet and send nothing. Check the physics layers.