Day 6: OnCollisionEnter Vs. OnTriggerEnter

Andrea Alicino
2 min readMar 23, 2021

Today's topic is collisions between two objects, Unity provides two ways to handle this problem, we must specify one thing, two objects can collide with each other or through each other without something happening between them.

To make this possible game objects must have a Rigidbody assigned between the components.

add Rigidbody to the player

Another essential element is the collider, there are different types of collider, cube, sphere, capsule or that follow the mesh of the model.

my Box Collider attached to Player

We can see that already in the collider box we have an “isTrigger” entry that allows us to decide if our game object should have collisions or can pass through objects.

Now we see the difference between these two methods.

if Is Trigger is true

the cubes pass-through the player and the bullets too

Game objects are passed through, but with the call of the OnTriggerEnter method, we can recognize a specific object and assign it a behavior to execute.

OnTriggerEnter example

In my example, the result is this

if Is trigger is false

If instead, we want to use collisions, the call remains similar but we go to look for the collision directly instead of the collider.
We need the “is trigger” entry to be false.

Same example with OnCollisionEnter

If you don’t handle the OnCollisionEnter method here is what could happen inside your game.

It could be a nice and very relaxing screensaver.

--

--

Andrea Alicino

Game Developer Unreal Engine/Unity. Computer science graduate. Seeking new opportunities.