OnCollisionEnter VS OnTriggerEnter
After adding a rigidbody component to an object in Unity, we also have access to a box collider; depending on what we want to simulate we’ll need to decide which of the two main ways we can handle a collision. Do we want objects that collide to shove each other, or do we want a cutscene to start when one object touches the other?
Using OnCollisionEnter will make Unity try to simulate real world physics. Things that collide with this method will be moved around and manipulated depending on their mass, gravity, and so on.
This will be great for simulating car crashes or anything that needs to follow the rules of momentum and force.
But in a game we don’t always need real world stuff. Sometimes we just need to trigger something when one object passes through another. For this we use OnTriggerEnter. This can be enabled simply by checking the box next to “isTrigger” in the box collider menu, and then calling up the method in the appropriate script.
This method is quite useful for activating cutscenes, collecting items, replenishing health bars, etc. Even for things that seem that they would need physics, may only need triggers. For instance, depending on the style of your game, you might need an attack to trigger the enemy’s hurt animation.
When determining which type of method to use, just think carefully on the reactions you want to make, and don’t be afraid of trail and error.