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.
| Field | Type | Description |
|---|---|---|
entityA | Entity | First entity in the collision pair |
entityB | Entity | Second entity in the collision pair |
normalX | number | Collision normal X component |
normalY | number | Collision normal Y component |
contactX | number | Contact point X in world space |
contactY | number | Contact point Y in world space |
Collision Exit
Fired on the first frame two non-sensor colliders stop touching.
| Field | Type | Description |
|---|---|---|
entityA | Entity | First entity in the collision pair |
entityB | Entity | Second entity in the collision pair |
Sensor Enter
Fired when a non-sensor collider begins overlapping a sensor collider.
| Field | Type | Description |
|---|---|---|
sensorEntity | Entity | Entity with isSensor = true |
visitorEntity | Entity | Entity that entered the sensor zone |
Sensor Exit
Fired when a non-sensor collider stops overlapping a sensor collider.
| Field | Type | Description |
|---|---|---|
sensorEntity | Entity | Entity with isSensor = true |
visitorEntity | Entity | Entity that left the sensor zone |
See Also
- Physics Overview — setup and configuration
- Colliders — collider shapes and sensor property
- API — runtime physics control