Rigidbody, Collision, Trigger, and Raycasting


For objects to take advantage of Unity’s built-in physics engine, they must include a component called a rigidbody. Adding a rigidbody component makes an object behave like a real-world solid entity.


For objects to detect collision, they need a component called a collider. A collider is a perimeter that is projected around your object that can detect when other objects enter it.

Note: rigidbodies are required for trigger collision

Physics Materials

Physics materials can be applied to colliders to give objected varied physical properties. For instance, you can use the rubber material to make an object bouncy or an ice material to make it slippery. You can even make your own to emulate a specific material of your choosing.


A trigger detects collision just like normal colliders do, but it doesn’t do anything specific about it. Instead, triggers call three specific methods that allow you, the programmer, to determine what the collision means

void OnTriggerEnter(Collider other)    //is called when an object enters the trigge

void OnTriggerStay(Collider other)     //is called when an object stays in the trigger

void OnTriggerExit(Collider other)     //is called when an object exits the trigger

Note: Triggers Not Working

For trigger colliders to work, a rigidbody must be involved. If an object without a rigidbody enters a trigger collider, nothing will happen. If you are noticing in your scene that some objects aren’t triggering the way you want, ensure that they have rigidbodies on them.


Raycasting is the act of sending out an imaginary line, a ray, and seeing what it hits. Imagine, for instance, looking through a telescope. Your line of sight is the ray, and whatever you can see at the other end is what your ray hits. Game developers use raycasting all the time for things like aiming, determining line of sight, gauging distance, and more. 

bool Raycast(Vector3 origin, Vector3 direction, float distance, LayerMask mask) ;

bool Raycast(Vector3 origin, Vector3 direction, out Raycast hit, float distance);