Effects of using OnCollisionEnter and OnTriggerEnter in Unity

Samarth Dhroov
2 min readMay 7, 2021

--

Collision

(If you have not gone through the physics in Unity article, please go through it before going further here.)

https://samarthdhroov.medium.com/thinking-to-mimic-the-real-world-in-your-game-unitys-physics-is-the-way-faa4bb51546e

Let me put this at the most basic level. onCollisionEnter method mimics a solid volume that enables bounce off of colliding objects whereas onTriggerEnter mimics an empty volume that triggers other events within the game.

Both methods deal with boundaries essentially.

For example, if you are looking for an accident wherein if two solids bump into each other, the effect should be either damage of significant level or complete destruction of both solids and eventually scattered broken parts all over the scene, you need to choose onCollisionEnter method. Of course, It’ll need a lot more than this method but this is a must :)

On the other side, if you are aiming at alarming your player with the presence of some CCTV cameras upon entering a certain section of a building, you need to choose onTriggerEnter method.

Below is the use of OnCollisionEnter( ). Observe how two blocks, upon accident, roam around in the no man’s land.

They are not letting each other pass through.

Unity

What do you think the OnTriggerEnter( ) would do? Let me make some changes in the script and tick the “Is Trigger” checkbox in the box collider component of both cubes.

Unity

As you saw, the collision changed the color of the cube to black. The trigger method and option in collaboration allowed two solid cubes to pass through them. The moment they did, the script had instruction in place and it triggered the color change.

They did let each other pass through even though they have a collider and a rigid body in place.

Unity
C#

So, choose either of the methods based on the task’s ambition.

Thank you very much

--

--

No responses yet