githubEdit

Physics Event Methods

Reference for physics collision and trigger events

Respond to physics collisions and triggers (powered by Rapier physics engine).


Event Methods

Method
Parameters
When Called

onCollisionEnter

Rigidbody starts colliding with another

onCollisionStay

Rigidbody continues colliding

onCollisionExit

Rigidbody stops colliding

onTriggerEnter

Collider enters a trigger zone

onTriggerStay

Collider stays in a trigger zone

onTriggerExit

Collider exits a trigger zone


Collision vs Trigger

Collisions:

  • Require Rigidbody components

  • Generate physical response (bounce, block)

  • Used for solid objects that interact physically

Triggers:

  • Mark collider as "Is Trigger" in Unity/Blender

  • No physical response (objects pass through)

  • Used for zones, pickups, detection areas


Collision Object

The Collisionarrow-up-right parameter provides information about the collision:


Example: Collision Detection


Example: Trigger Zone


Requirements

For physics events to work:

  1. GameObject must have a Collider component (BoxCollider, SphereCollider, etc.)

  2. For collision events: GameObject needs a Rigidbody component

  3. For trigger events: Collider must be marked as "Is Trigger"


Performance Tips

  • Use triggers instead of collisions when physical response isn't needed

  • Keep onCollisionStay and onTriggerStay logic lightweight (called every frame)

  • Consider using layers to filter what collides with what


Last updated