Playing with Collisions and Triggers

Janika Suhonen
3 min readApr 12, 2021

More about OnCollisionEnter and OnTriggerEnter

Collisions

How to use collisions? Well…

For this little testing, you need colliders and rigidbodies! :)

I recommend you try out how everything works and just play with this and have fun! :D

Collision
OnCollisionEnter, CompareTag

In this example, I used OnCollisionEnter to see if the game object we collisions with was tagged as a player. And when that happened, our main cubes speed was set to 0f.

See if the object has “Player” tag

Rigidbodies can be used to add mass & drag to an object. You can also choose if it uses gravity or is it just kinematic.

The more you have drag, the slower it will drop down.

And the more you have mass, the faster it drops down. But… if the cube would be on the ground and something would collide with it. The cube wouldn’t move much because of the mass.

Mass and drag test

Triggers

Triggers are good to play a certain music track, change color, move an object up or anywhere you want. Triggers are used on soft collisions as I described before.

OnTriggerEnter & OnTriggerExit
Move cube up 2f

Making the cube go up I used transform.Translate and of course when the player triggers this again the cube will go up again by 2f. :D

Translate cube up by 2f

But which one to choose? And why?

If you want soft collisions as I described before with the color change or music… Triggers are good for that.

But if you want hard collisions like crashes or falling from the sky onto the ground, then you should use collision.

That’s it for now…

Thank you for reading! Much love & see you in the next one! :)

--

--

Janika Suhonen

From the beautiful snowy country with a touch of "good" humor? Inspired Unity Developer to learn more.