OnCollisionEnter vs OnTriggerEnter

How do I use them?

In order to use OnTriggerEnter we need to add a rigidbody component to our gameobject/s.

RigidBody added to sphere.

Ticking use gravity will produce similar to below.

In order for us to have the sphere do more than roll off the surface, we need to

attach a script to the gameobject. In the script, if we have:

Then we also need to click on Is Trigger in the collider of the object.

Make sure Is Trigger is ticked.

And the below will happen, instead of rolling off:

Now, if we remove the script, still keeping is trigger ticked the below will happen:

Since there is no script telling the sphere what to do when it encounters another collider it just goes straight through the other object.

Now, if we add a rigidbody component to the rectangle as well, and not have gravity ticked on the rectangle. Also, making sure that Is Trigger is not ticked on both. The below will happen when started.

Then changing the script on the sphere to (similar to above):

The below will happen.

Note inside the brackets of the void also needs to change to Collision.

As can be seen, the sphere adds a force to the rectangle when it touches the rectangle and then transports to its starting position.