When to use OnCollisionEnter() and OnTriggerEnter()
Have you ever noticed that little checkbox in your Collider component that says “Is Trigger”?
That’s the one I’m talking about. Basically, it removes the colliding function of your collider. Why would we want that? Isn’t that what a collider is for? Well, yes but…
It’s better to think of a collider more like a defined zone. Essentially, any space in the world that we want to keep an eye on. There could be many reasons for this.
For example, what if I wanted to change the colour of the ball when it passes a certain point? Well, we can define that point using a collider and since we don’t want it to stop we can set it to a trigger. It will simply turn red as it passes through like so:
My favourite trick is to disable the MeshRenderer on the trigger so that the object becomes invisible! That way you can mark points in the game world that warrant special behaviours and the player will have no idea! Just like this:
So now, when the ball passes through the invisible trigger it will still turn red, but the player will have no idea that the trigger is there!