OnCollisionEnter Vs. OnTriggerEnter — When to use them?

Marc Frappier
3 min readApr 10, 2021

When two objects in a game collide, it can be handled in several different ways. Do we want the objects to actually hit each other and change direction or one stops the other or maybe we just need the information that one object collided with the other in order to trigger a reaction.

If we want to only trigger a reaction, we need to use the onTriggerEnter.

onTriggerEnter

onTriggerEnter

In this scenario, all objects must have a collider component. In our case, when we create a gameObject it automatically gets a Box Collider.

Box Collider Component

One of the components must have the Is Trigger enabled and have a Rigidbody component. We can add the Rigidbody component by selecting the object, going to Add Component and selecting Rigidbody.

Adding a Rigidbody to an object

With the onTriggerEnter, we can start an action, like a powerup or collecting items or as in the animation, making the ball go in the other direction.

onTriggerEnter condition

onCollisionEnter

This acts as a real collision, a physical collision.

This is possible when at least one of the objects has a Rigidbody or if they both have Rigidbodies, then one must have the isKinematic as true. In this case, the platform would have the isKinetatic as true and the ball would just have the Rigidbody and gravity activated.

Now, if either of these object has the is Trigger activated, they will not collide as they will send the onTriggerEnter instead.

If both objects have Rigidbodies and neither is Kinematic then they will react upon collision.

In this case, the ball has a Rigidbody with gravity enabled, the platform has a Rigidbody with nothing enabled (no gravity and no Kinematic).

Basically, if you need one object to react to another, you need to set it up as a onCollisionEnter. But most of the time, you will most likely be using the “collision” of objects as a trigger with onTriggerEnter to do something else.

--

--

Marc Frappier

Poultry Scientist by profession, Computer Scientist at heart. After many years in the poultry business, I have decided to give my passion for technology a shot.