OnCollisionEnter Vs. OnTriggerEnter — When to use them?

Adding to the physics in unity topic we have two methods we can call that effect our game objects. In my previous example i used OnTriggerEnter

Which activated the destroy game object instruction. this works because both objects have colliders components attached.

in the unity documentation is it explained like:

Both GameObjects must contain a Collider component. One must have Collider.isTrigger enabled, and contain a Rigidbody. If both GameObjects have Collider.isTrigger enabled, no collision happens. The same applies when both GameObjects do not have a Rigidbody component.

the other OnCollisionEnter can be used when collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached. For example if we wanted to trigger a finishing line to trigger the end of a race. Gameobjects can pass through each other and an event can take place.



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