When you create a 3D model, you will find an item called a ‘Collider’ in the Inspector window.
A collider is a function that can apply physical laws (physic rules) (such as gravity or colliding) to models in a scene, like real life objects.
Objects without colliders will pass through without colliding, just as in the GIF image below.
If you want to create an animation where a Sphere impacts a surface when colliding into it, or slows down, you need to understand the collider function.
In this article, I will go through a tutorial to create a Scene in which a sphere rolls down a slope. I will explain the details of the collider function.
Preparation
Shape Settings
Let’s create the Plane that will become the slope and the Sphere that will roll on it.
Once you create the Plane, change the Transform values to that in the image below.
Next, after you create the Sphere, change the Transform values to that in the image below.
Main Camera Settings
Now that you have created the objects, let’s see how they look in the scene.
You can check this by clicking the Play button located at the top of the Scene.
By the way, clicking on the play button is called ‘running’ the game or project.
Although we have run the project, you cannot see anything in the Scene.
This is because the viewpoint is from the Main Camera and the objects are not within the Main Camera’s view.
Please set the Main Camera Transform values in the Inspector window to those in the image below.
Run the project again.
You can now see the objects in the Scene.
Adding a Rigidbody to the Sphere
The Sphere is still and doesn’t roll down the slope. This is because the Sphere does not have any physic functions applied to it.
So, we will set a function called Rigidbody to the Sphere, which applies physic rules to the object.
Select Add Component → Physics which is located at the bottom of the Sphere Inspector window.
Select Rigidbody
Rigidbody is now added to the Inspector window of the Sphere.
You do not need to change the values, but do not forget to set the ‘Use Gravity’ option. This is a function that adds gravity to a model.
Let’s run the Scene. You can see the Sphere will roll down the Plane now.
Collider Settings
Edit Collider
Select the Sphere, and choose ‘Sphere Collider’ → ‘Edit Collider’ from the Inspector window.
Dots will appear around the Sphere.
These dots will detect if the Sphere collides with something.
Grab the bottom dot and pull it downwards.
By doing so, the Sphere shape does not look different, but when it collides with something else, it will count as a larger object.
Let’s run the Scene again.
You can see that the Sphere will collide with the Plane much earlier than before, since the collider is larger.
Is Trigger
You do not need to understand this function yet, but the ‘Is Trigger’ is used when you want to create an event when something occurs.
If you start using Playmaker or scripts with objects, you might need to use the Is Trigger, so just keep it in mind for now.
Collider
We have gone through the basics of the collider function, but I want to explain one more function called the ‘Mesh Collider’.
You should find a component named ‘Mesh Collider’ within the Inspector window of the Plane. The box is checked right now.
Try unchecking this box and run the Scene.
The Sphere falls right through the Plane.
This is because the Mesh Collider is the function that detects whether the object is colliding with a surface or other object.
The ‘Sphere Collider’, which you can find in the Sphere Inspector window has similar features. If you uncheck it, the Sphere will go through the Plane.
Always remember that a Collider is a function that detects a collision with another object.