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!




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Testing in Node.js: Easy way to mock filesystem

A Deep dive into methods available on Objects In javascript

Spread and Rest Operator in JavaScript

Common Mistakes in React and Next.js

SORA Ledger app + Polkadot.js.org/apps

Hilarious Programming Jokes Guaranteed to Make Anyone Laugh

React Native Phone Number Input

Offline Storage with IndexedDB — Part 2

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Justen Chong

Justen Chong

More from Medium

2D Mobile: Designing Enemies Using Abstract Classes

Installing the Universal Render Pipeline in Unity 2021.2

Creating A Respawn/Checkpoint System In Unity

Easy Way to Make an Audio Slider