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 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 in where a Sphere bumps when colliding to another object, or slows down, you need to understand the collider function.
In this article, I will go through a tutorial to create a Scene in where a sphere rolls down a slope, and explain details of the collider function.
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 of the image below.
Next, after you create the Sphere, change the Transform values to that of the image below.
Main Camera Settings
Now you have created the objects, let’s see how they look in the scene.
You can check this by clicking the Play button located on top of the Scene.
By the way, clicking on the play button is called ‘running’ the game or project.
Although we have runned 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 view.
Please set the Main Camera Transform values in the Inspector window to those of the image below.
Run the project again.
You can now see the objects in the Scene.
Adding a Rigidbody to the Sphere
But the Sphere is still, and doesn’t roll down. This is because the Sphere does not have any physics functions applied to it.
So, we will set a function called Rigidbody to the Sphere, which applies physics rules to the object.
Select Add Component → Physics which is located at the bottom of the Sphere Inspector window.
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 the function to add gravity to a model.
Let’s run the Scene. You can see the Sphere will roll down the Plane now.
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.
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.
We have gone through the basics of the collider function, but I will just explain about one more function, 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 the 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 another.
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.
Let’s memorize that Colliders are the functions that detect collision with other objects.