Using Mesh Colliders

Simon Pham
3 min readApr 29, 2024

--

In our previous blog posts, we discussed using Primitive Colliders. Today, let’s delve into Mesh Colliders.

What is a Mesh Collider?

A Mesh Collider is a component that provides collision detection based on the actual mesh geometry of a GameObject. Unlike Primitive Colliders, which use simple shapes for collision detection, a Mesh Collider uses the detailed mesh of an object for more accurate and complex collision interactions.

Mesh Collider demonstration

I’m gonna use a barrel to demonstrate how a Mesh Collider works.

Next, I’m gonna add a Rigidbody and a Mesh Collider component to the barrel.

Let’s see what happens when I hit the Play button.

As you can see, the barrel fell through the ground and also I got an error message in the console.

The reason for that is because from Unity 5 onwards, using a non-convex mesh collider requires a kinematic Rigidbody. So how do the convex and kinematic properties affect our GameObject in Unity?

Convex vs non-convex mesh colliders

Convex mesh collider

A convex mesh collider will ignore any indentations that an object has and you can enable it by checking the Convex option in the Mesh Collider component.

Here’s what it looks like:

And it will treat the top of the barrel like a flat surface.

Non-convex mesh collider

Contrary to convex mesh colliders, non-convex mesh colliders accurately represent the shape of GameObjects including any indentations. These colliders are not visible, but they do interact with the environment.

And in order for non-convex mesh colliders to work, you will need to use a kinematic Rigidbody which will make our GameObject not affected by external forces like gravity or collisions with other objects.

And here’s the result:

--

--

No responses yet