OnCollisionEnter vs. OnTriggerEnter

--

Figuring out when to use these are very important!

First thing’s first, these functions deal with both the Collider Components and Rigidbody Components for Unity.

Rigidbodies allow for Physics while Colliders allow for Interactions

OnCollisionEnter() is a function that executes its code when to objects… well, collide! It tends to deal with physics interactions. Some examples would be the ground of pretty much any game ever or a bouncy ball hitting a wall.

OnTriggerEnter() is instead used when you want something to happen to the object in question. Think of the coins in Mario or a Hadouken in Street Fighter. Something other than physics happens to the respective objects.

When the capsule collides with the red cube, OnTriggerEnter() is called and destroys both objects

I hope this quick little blurb of an article helps you better understand the difference next time you need some collisions!

--

--