Sitemap

Detection of Collision.

2 min readMay 11, 2025

Objective: Detection of Collision.

Before starting anything, let's understand that detecting collision using Trigger differs from this one.

Trigger uses Collider when is Trigger property is enabled, meaning the object must have a collider, but also the isTrigger must be enabled.

Note: We use OnTriggerEnter to detect collision, plus this object it not necessarily to have a rigidbody; at least one of those objects needs to have a rigidbody.

Detection of Collision Using RigidBody.

The object that wants to detect a collision must have a rigid body on it.

Note: It will work when collider with objects that both have a rigidbody and a collider. But collide with a static object which have a collider; only this object must have a rigidbody.

This object has a script called DetectCollisions, but to detect collision on a Rigidbody, we need to use OnCollisionEnter.

Note: This method passes the Collision Class and not Collider like OnTriggerEnter(Collider other).

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

To detect a specific object, we will use the tag to narrow down those objects.

Note: CompareTag is more optimized than:

collision.gameObject.tag == “Hazard”.

See you in the next one.

--

--

Suleiman Abdullah
Suleiman Abdullah

Written by Suleiman Abdullah

Self taught Unity Developer, who is passion about making games ,and he loves Math For Game Development

Responses (1)