How to Create Colliders on Objects in Unity
Colliders are one of the most fundamental building blocks in Unity game development. Whether you're making a platformer, a racing game, or a 3D physics simulation, colliders define how objects interact with each other physically — controlling everything from bouncing and sliding to triggering events when a player enters a zone. Understanding how to add and configure them correctly makes the difference between a game that feels solid and one that feels broken.
What Is a Collider in Unity?
A collider is an invisible shape attached to a GameObject that Unity's physics engine uses to detect contact and collisions. It doesn't have to match the visual mesh of the object exactly — in fact, for performance reasons, it usually shouldn't.
Unity separates the visual representation (the mesh renderer) from the physical representation (the collider). This means you can have a complex 3D model rendered on screen while the physics engine interacts with a much simpler shape underneath.
Types of Colliders Available in Unity
Unity offers several collider types, each suited to different situations:
| Collider Type | Shape | Best Used For |
|---|---|---|
| Box Collider | Rectangular box | Walls, floors, crates, platforms |
| Sphere Collider | Sphere | Balls, projectiles, rounded objects |
| Capsule Collider | Cylinder with rounded ends | Player characters, NPCs |
| Mesh Collider | Exact mesh shape | Detailed terrain or static objects |
| Wheel Collider | Specialized wheel physics | Vehicle wheels |
| Terrain Collider | Matches Unity Terrain asset | Large terrain surfaces |
For 2D projects, Unity has equivalent 2D versions: Box Collider 2D, Circle Collider 2D, Polygon Collider 2D, and Edge Collider 2D.
How to Add a Collider to a GameObject 🎮
Method 1: Using the Inspector
- Select your GameObject in the Hierarchy panel.
- In the Inspector, click Add Component.
- Search for the collider type you want (e.g., "Box Collider").
- Click it to attach it to the object.
Once added, the collider appears as a green outline around your object in the Scene view. You can toggle visibility using the Gizmos button in the Scene view toolbar.
Method 2: Adding via the Menu Bar
With your GameObject selected:
- Go to Component → Physics → [Collider Type] for 3D projects
- Go to Component → Physics 2D → [Collider Type] for 2D projects
Method 3: Adding at Runtime via Script
You can also attach colliders through C# code: