Unity Fundamentals — Collisions and Triggers.

Jose Gil
2 min readApr 7, 2021

--

As a game designer, you will have situations when you want your GameObjects to interact with each other in different ways. You may want to destroy an object hit by a bullet, open a door, crash a car or even trigger an alarm.

As a game developer, you can achieve these objectives using Unity’s Collision methods of OnCollisionEnter and OnTriggerEnter. Both of these based on a RigidBody and a Collider come into contact.

void OnCollisionEnter(Collision, Other)void OnTriggerEnter(Collider, Other)

Other Collider methods are available, but these two are the most common, and I will focus this article on these.

OnCollisionEnter

Taking the Collision parameter, it contains a lot of information, including impact velocity and contact points. A RigidBody must be attached to the GameObject for this method to work.

OnTriggerEnter

Taking the Collider parameter, it returns the information on the GameObject that collided with it. Both GameObjects must contain the Collider component for this method to work. Also, one GameObject must have the isTrigger in the Collider enabled with a Rigidbody component. Please note that if both GameObjects have the isTrigger enabled in the Collider, no collision will be detected.

When and which to use.

If you consider the terms Trigger and Collision, when and which to use is self-explanatory. Even though you can use either one to achieve the same result like destroying a GameObject, at Mooski Games, we try to use them in the following way

  • OnTriggerEnter is used to trigger an event that is to occur when GameObjects collide.
  • OnCollisionEnter is used when an impact is needed when GameObjects collide.

I hope this article has helped you in your game development journey with Unity.

--

--

Jose Gil
Jose Gil

Written by Jose Gil

Unity Developer at Mooski Games

No responses yet