Collision VS Trigger!

addam davis
2 min readMay 12, 2021

--

Last time, we used the method OnTriggerEnter, and I’m going to explain why we chose that method, what the other methods are and how to choose what method is right for you!

In MonoBehaviour there are 6 messages we are going to discuss. They are OnCollisionEnter, OnCollisionExit, OnCollisionStay, onTriggerEnter, OnTriggerExit, and OnTriggerStay.

OnCollisionEnter is called when a rigidbody/collider has begun touching another rigidbody/collider.

OnCollisionExit is called when this rigidbody/collider stops touching another rigidbody/collider.

OnCollisionStay is called once per frame for every rigidbody/collider that is touching rigidbody/collider.

OnTriggerEnter happens on the fixedupdate function when two gameobjects collide.

OnTriggerExit is called when the collider has stopped touching the trigger.

OnTriggerStay is called once per physics update for every collider that is touching the trigger.

To think of it in a more basic way, Enter is when two objects make contact, Exit is when the two let go and Stay is while they are in contact. OnCollision is used to create collision between objects. The gameObjects will collide and be repelled by their forces.

OnTrigger is used to detect collision but not act as a solid, instead it allows the gameobjects to pass through. To use the trigger function, you must have trigger selected in the box collider component on the inspector view. Also, for the OnTrigger to work properly one of the gameObjects must have a rigidbody attached to it.

On the last lesson we wanted our player to pass through the enemy like we were collecting a powerup or a collectable, so we used the trigger function.

know that you have the knowledge of collisions you will be able to implement them into your game and create obstacles for your player to work around.

--

--