OnCollisionEnter vs OnTriggerEnter — When to use them
We know we need colliders so objects can interact with each other. Say I want to make a “danger zone” that warns Ethan when he gets near the edge of the floor so our bro doesn’t fall into the abyss. We can do this by making an invisible block, giving it a box collider, and checking “Is Trigger” on its collider component.
We tell the danger zone’s OnTriggerEnter method to change the material of the floor to red when Ethen enters the danger zone, and the OnTriggerExit method to change it back to light blue when he leaves.
Now, Ethan can still pass through the danger zone and fall off the edge. So let’s save him from himself. We uncheck “Is Trigger” on the danger zone. Now when Ethan touches the danger zone, it stops him because it’s considered a solid object, but Unity’s physic’s engine also calls the danger zone’s OnCollisionEnter method. We’ll have this method change the danger zone’s material to a transparent yellow so it looks like a force field. When Ethan leaves the danger zone, OnCollisionExit is called, which disables the danger zone’s Mesh Renderer, making it invisible again.
OnTriggerEnter is great for making collectibles like the rings that super-fast spikey blue rodent collects.
OnColliderEnter will enable your player’s foes to damage your players and block their progress!