OnCollisionEnter Vs. OnTriggerEnter — When to use them?

Rusben Guzman
2 min readMay 18, 2021

--

Unity provides two different methods to detect collisions between game objects, OnCollisionEnter is used to detect hard collisions like a player touching a wall or two cars crashing on the flip side OnTriggerEnter detects soft collisions like picking a coin or power up. Now let’s do a simple example of how to use each one.

The first step in both cases is that one of your game objects has to contain a Rigidbody Component.

OnCollisionEnter:

In order to use this the field “Is Trigger” in the collider component has to be unchecked.

Now in the Script we have to add the function OnCollisionEnter:

And within the function we can add the action we gonna executo when the objects collide, in this case we gonna change the color of the object the player collide with:

OnTriggerEnter:

In this case the “Is Trigger” field in the collider component has to be checked.

Then we add the OnTriggerEnter function and the actions we want to run, in this case we gonna simulate to pick up a coin from a game, so the coin have to disappeared and we gonna increase the score:

--

--

Rusben Guzman
Rusben Guzman

Written by Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

No responses yet