Detection of Collision.
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).
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.