Collisions in Unity

In Unity collisions are handled in two different ways - colliding with another object and physically react (OnCollision), or ignore the physics and just detect (OnTrigger). Below I will go over the functions that get called during these collisions.

On every collider component there is a check box if an object should physically react or just detect when colliding with another object:

There are 6 function calls in total = 3 for OnCollision and 3 for OnTrigger:

01. OnCollisionEnter
This is called the moment an object hits another object:

02. OnCollisionExit
This is called the moment an object stops colliding:

03. OnCollisionStay
This function is called every frame while the object is still colliding with another object:

04. OnTriggerEnter
This is called the moment an object enters another object with Is Trigger enabled:

05. OnTriggerExit
This is called the moment an object exits another object with Is Trigger enabled:

06. OnTriggerStay
This is called every frame an object is inside another object with Is Trigger enabled:

Good luck!

--

--

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