Effects of using OnCollisionEnter and OnTriggerEnter in Unity
(If you have not gone through the physics in Unity article, please go through it before going further here.)
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.
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.
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.
So, choose either of the methods based on the task’s ambition.
Thank you very much