Skip to content

Collision Events

Read collision and sensor events from the PhysicsEvents resource each frame.

PhysicsEvents Resource

import { defineSystem, addSystem, Res } from 'esengine';
import { PhysicsEvents } from 'esengine/physics';
addSystem(defineSystem(
[Res(PhysicsEvents)],
(events) => {
for (const e of events.collisionEnters) {
// e.entityA, e.entityB, e.normalX, e.normalY, e.contactX, e.contactY
}
for (const e of events.collisionExits) {
// e.entityA, e.entityB
}
for (const e of events.sensorEnters) {
// e.sensorEntity, e.visitorEntity
}
for (const e of events.sensorExits) {
// e.sensorEntity, e.visitorEntity
}
}
));

Event Types

Collision Enter

Fired on the first frame two non-sensor colliders begin touching.

FieldTypeDescription
entityAEntityFirst entity in the collision pair
entityBEntitySecond entity in the collision pair
normalXnumberCollision normal X component
normalYnumberCollision normal Y component
contactXnumberContact point X in world space
contactYnumberContact point Y in world space

Collision Exit

Fired on the first frame two non-sensor colliders stop touching.

FieldTypeDescription
entityAEntityFirst entity in the collision pair
entityBEntitySecond entity in the collision pair

Sensor Enter

Fired when a non-sensor collider begins overlapping a sensor collider.

FieldTypeDescription
sensorEntityEntityEntity with isSensor = true
visitorEntityEntityEntity that entered the sensor zone

Sensor Exit

Fired when a non-sensor collider stops overlapping a sensor collider.

FieldTypeDescription
sensorEntityEntityEntity with isSensor = true
visitorEntityEntityEntity that left the sensor zone

See Also