【Unity Tutorial】Learning about Colliders

When you create a 3D model, you will find an item called a ‘Collider’ in the Inspector window.

Checking a Collider

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.

When there are no colliders

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.

With colliders

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 of the image below.

Plane Transform settings

Next, after you create the Sphere, change the Transform values to that of the image below.

Sphere settings

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.

Play Button

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.

Running the project

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.

Main Camera Settings

Run the project again.

You can now see the objects in the Scene.

The Sphere does not move

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.

Select Physics

Select Rigidbody

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 the function to add gravity to a model.

Rigidbody Settings

Let’s run the Scene. You can see the Sphere will roll down the Plane now.

After applying Rigidbody

Collider Settings

Edit Collider

Select the Sphere, and choose ‘Sphere Collider’ → ‘Edit Collider’ from the Inspector window.

Select Edit Collider

Dots will appear around the Sphere.

These dots will detect if the Sphere collides with something.

Grab the bottom dot and pull it downwards.

Expanding the collider shape

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.

We can see the shape of the collider has changed.

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.

Is Trigger checkbox

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 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.

Plane Inspector window

The Sphere falls right through the Plane.

When the Mesh Collider is non active

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.