OnTriggerEnter or OnCollisionEnter? When Should You Use Them & How?
OnTriggerEnter = Passthrough Collisions
This is called whenever an object with a collider passes through an object with a collider that has “isTrigger” checked.
You’ll want to use collision detection like this when you are detecting the collision for the purpose of triggering some form of function such as dealing damage or picking up objects.
OnTriggerEnter happens on the FixedUpdate function when two GameObjects collide. The Colliders involved are not always at the point of initial contact.
OnCollisionEnter = Hard Collisions
OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
Collision detection like this is used more for physics and objects that don’t allow things to pass through them. This can be useful if you need to detect when the player comes in contact with a wall or obstacle of sorts.
In contrast to OnTriggerEnter, OnCollisionEnter is passed through the Collision class and not a Collider. The Collision class contains information about contact points and impact velocity.
[Note]
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.
How Do I Use Them?
Well, since both OnTriggerEnter and OnCollisionEnter function in essentially the same way, the syntax isn’t really different. the real main difference is when to use them which is explained in the last section. So for this example, I will be using OnTriggerEnter to detect when an enemy object gets shot with a laser.