Unity Physics: Collider Basics
When it comes to collisions in Unity, the collider component is your best friend! While Unity has some more advanced colliders like Mesh, Terrain and Wheel colliders, I will cover the basic primitive colliders in this article.
Box Collider
The box collider is arguably the most used collider. It works great for quickly sketching out a level design with cube primitives, as well as handling basic collisions on a lot of smaller objects. I want physics based hard-surface collisions, so the Is Trigger box must be un-ticked.
When you add a box collider component to a game object, the collider will use the mesh filter to estimate and snap to the shape of the object.
This button is used for manually editing the collider.
You can edit the radius and height values, as well as using the small square handles shown below to manually adjust the size of the collider.
Capsule Collider
If the box collider does not fit the job, the capsule collider is great for elongated non-spherical shapes.
This barrel here is a good example of an object that is not a sphere, but still needs to roll around the room if knocked over. The box collider will not work here for that behavior, so the capsule collider comes to the rescue.
Sphere Collider
I did not need a sphere collider for this small scene, but it is there for you if you need it. Sphere colliders are perfect for sports balls and other spherical objects.
Compound Colliders
Compound colliders are when you use multiple colliders on one game object. No matter how many colliders of any one type you place on a game object, the edit collider button will only show on the top-most of each collider type. This light here gets a capsule collider as it’s base collider.
Box colliders are added to new empty children objects in order to properly rotate them into the needed 45 degree angle for these tri-pod legs.
It is especially useful to use the orthographic camera view and snap to your axes, to get the best visual representation of your colliders when adjusting their size. The below image is offset to show all three leg colliders after adjustment.
A similar approach is used here for the feet. It is up to you to decide how complicated these colliders need to be for your game. Ideally for optimization, it is best to use the most simple collider solution you can for your behavior needs.
This other light object is only using three colliders. Two box colliders are good enough to cover much of the model.
A capsule collider finishes the middle.
I hope you enjoyed this introduction to colliders in Unity. I wish you the best in your game development journey and thanks for reading!