OnCollisionEnter Vs. OnTriggerEnter

By default, GameObjects with a Rigidbody component applied will be blocked (collided) by the Collider. While Colliders can block Rigidbodies, they can also be used as Triggers. When a Collider is set as a Trigger, it detects external interactions from other game objects and executes code that is within a OnTriggerEnter, OnTriggerExit, or OnTriggerStay function within a script.

Let there be a sphere and below the sphere place a cube. Rigidbody is applied to the sphere, so it falls. A collision is detected and the Player(Sphere) is stopped , this is what we called hard collisions. If we apply trigger the collision occurs but the Player passes through it.

Collsion

Create a Player Script and attach it to the Player gameObject .Let's check now when the player falls and hit the wall the collision is detected using the code

collision Detection

OnCollisionEnter method detects the Hard Surface Collision.

When we enable Trigger for the Player , the collision is detected using OnTriggerEnter method. Though the object passes the collision is detected using the code .

OnTriggerEnter

OnCollisionEnter () and OnTriggerEnter() both are the methods of the Collider Class. Both are used to detect collisions when colliders enter the collision but both perform differently and cause different events.

OnTriggerEnter() is used to detect collision but it does not act as solid body , rather allows the gameobjects to pass through them. To use OnTriggerEnter() , the IsTrigger property of the collider should be checked. To get trigger event to work properly a rigid body must be attached to one of the colliding gameobject.

OnCollisionenter() is used to create Collisions between objects. Gameobjects collide with each other and get repelled by their forces.
To use OnCollisionEnter(), a collider must be attached to the gameobject and its IsTrigger property should unchecked and in order to receive a physical collision event one of the colliding gameobject must have rigid body attached to itself.