What colliders do and where to add them

A collider in Unity is an invisible shape attached to a game object that tells the physics engine where that object's solid boundaries are. When two colliders touch, Unity can detect the collision, stop objects from passing through each other, or trigger events in your code. Without a collider, an object exists visually but has no physical presence — other objects pass straight through it.

Colliders live on the same game object as your 3D model or sprite. You add them through the Inspector panel while the object is selected, and you can add multiple colliders to a single object if its shape is complex. The most common colliders are Box, Sphere, and Capsule for simple shapes, and Mesh Collider for detailed geometry.

Every collider needs a Rigidbody component on the same object if you want physics to affect it — gravity, forces, or collision responses. If the object should stay still (like a wall or platform), you can use a collider without a Rigidbody, and it becomes a static collider that other objects bounce off.

Key Takeaways

  • Add a collider by selecting your object, opening the Inspector, clicking Add Component, and choosing Box Collider, Sphere Collider, Capsule Collider, or Mesh Collider depending on your object's shape.
  • A Rigidbody component on the same object lets gravity and physics affect the collider; without it, the collider stays in place and acts as a wall.
  • Adjust the collider's size and position in the Inspector so it matches your object's visible shape, or it will collide in the wrong places.
  • Use Box Collider for rectangular objects, Sphere Collider for round objects, Capsule Collider for characters or cylinders, and Mesh Collider for complex shapes.
  • Set the Rigidbody's Body Type to Dynamic if the object should move and be affected by physics, or Kinematic if you control its movement through code.

Adding a collider to a new object

Start by selecting the game object in the Hierarchy panel. If you do not have an object yet, create one: right-click in the Hierarchy, choose 3D Object, and pick a shape like Cube or Sphere. Once the object is selected, look at the Inspector panel on the right side of the screen.

At the bottom of the Inspector, click the Add Component button. A search box appears. Type the name of the collider you want — for example, "Box Collider" — and click it when it shows up in the dropdown. The collider component is now attached to your object and appears in the Inspector as a new section with adjustable settings.

The collider is now active, but it may not match your object's exact shape or size. You will see a green wireframe outline on your object in the Scene view showing the collider's boundaries. If this outline does not match your object, you need to adjust the collider's size and position.

Matching the collider to your object's shape

In the Inspector, find the collider component you just added. You will see fields for Size (or Radius for spheres) and Center. The Center is the collider's position relative to the object's center point — usually (0, 0, 0) means the collider is centered on the object.

For a Box Collider, change the Size X, Y, and Z values to match your object's width, height, and depth. Look at the green wireframe in the Scene view as you adjust — it should wrap snugly around your object without huge gaps or overlapping the edges. If your object is 2 units wide, 3 units tall, and 1 unit deep, set Size to (2, 3, 1).

For a Sphere Collider, adjust only the Radius value. For a Capsule Collider, set the Height and Radius. If your collider is off to one side, change the Center values to move it. For example, if your object is floating above the ground, increase the Center Y value to move the collider up.

Test your collider by entering Play mode (press the Play button at the top of the editor). Drop your object or move it toward another collider and watch whether it stops at the right place. If it stops too early or too late, go back and adjust the size and center values.

Adding a Rigidbody so physics affects your object

With your object still selected, click Add Component again and search for "Rigidbody". Click it to add the component. The Rigidbody tells Unity's physics engine to apply gravity, velocity, and forces to this object.

In the Rigidbody settings, you will see a Body Type dropdown. Choose Dynamic if your object should fall, roll, or be pushed by other objects. Choose Kinematic if you want to move the object through code (like a moving platform or a character you control) but you do not want gravity to pull it down. Choose Static if the object should never move — this is useful for walls, floors, or scenery.

Below Body Type, you will see Mass. This controls how heavy the object is. A heavier object is harder to push and falls faster. For most objects, the default value of 1 works fine. Increase it if you want the object to feel very heavy, or decrease it for light objects.

Freeze Rotation and Freeze Position are checkboxes that lock movement on specific axes. If your object is spinning wildly when it should stay upright, check Freeze Rotation Z (for 2D games) or Freeze Rotation X and Z (for 3D games where you only want rotation around the Y axis). If your object should not move up and down, check Freeze Position Y.

Choosing the right collider type for your object

Box Collider is the fastest and most common choice. Use it for cubes, walls, platforms, boxes, and anything roughly rectangular. It is efficient because the physics engine only needs to check if two boxes overlap.

Sphere Collider works for balls, spheres, and round objects. It is also very fast. Use it when your object is roughly spherical or when you want a collider that rolls smoothly.

Capsule Collider is a cylinder with rounded ends. It is the standard choice for character controllers and humanoid shapes because it does not get stuck on corners as easily as a box. If you are building a player character or enemy, start with a Capsule Collider.

Mesh Collider reads the exact shape of your 3D model's mesh. It is the most accurate but also the slowest. Use it only when your object has a complex shape that Box, Sphere, or Capsule cannot represent — like a detailed rock or an irregular building. For performance, avoid Mesh Collider on objects that move or collide frequently.

Handling collisions in code

Once your colliders are set up, you can detect when they touch by writing code in a C# script. Attach a script to your object by clicking Add Component, searching for "New Script", and naming it. Open the script in your code editor.

Inside the script, write a function called OnCollisionEnter to run code when this object hits another collider. For example:

void OnCollisionEnter(Collision collision) { Debug.Log("Hit something!"); }

The collision parameter tells you what the object hit. You can check the name of the other object with collision.gameObject.name or apply forces with collision.rigidbody.AddForce. Use OnCollisionStay to run code every frame while two colliders are touching, and OnCollisionExit to run code when they stop touching.

If you want collisions to trigger events but not physically stop objects, use a Trigger instead. Check the "Is Trigger" box on your collider, remove the Rigidbody (or set it to Kinematic), and use OnTriggerEnter, OnTriggerStay, and OnTriggerExit in your code instead.

Common collider problems and how to fix them

Objects pass through each other: Make sure both objects have colliders. If one object is moving very fast, it might pass through the other in a single frame. On the faster object's Rigidbody, change Collision Detection from Discrete to Continuous or Continuous Dynamic.

Collider is in the wrong place: Adjust the Center values in the collider component. If your object's mesh is offset from its center point, the collider will be too. You can also move the collider by changing its position, or move the mesh itself in your 3D modeling software.

Object falls through the floor: Make sure the floor has a collider (usually a Box Collider with Body Type set to Static). Make sure your falling object has a Rigidbody with Body Type set to Dynamic. Check that the floor's collider is not set to Is Trigger — triggers do not stop objects, they only detect when something enters.

Object is bouncing or jittering: Lower the Bounciness value on the Rigidbody's Physics Material, or set it to 0. If the object is jittering in place, increase the Mass or lower the Gravity Scale. You can also increase the Rigidbody's Drag value to slow it down.

Frequently Asked Questions

Do I need a Rigidbody for every collider?

No. A collider without a Rigidbody acts as a static collider — it stays in place and other objects bounce off it. Use this for walls, floors, and scenery. Add a Rigidbody only if you want gravity, forces, or physics to move the object.

What is the difference between a collider and a trigger?

A collider stops objects from passing through each other. A trigger (collider with Is Trigger checked) lets objects pass through but detects when they do. Use triggers for doorways, checkpoints, or areas that detect when the player enters.

Can I use a Mesh Collider on a moving object?

You can, but it is slow. Mesh Colliders are expensive for the physics engine to calculate, especially if the object moves or collides often. Use Box, Sphere, or Capsule Collider instead, or use Mesh Collider only on static objects like buildings or terrain.

Why is my character getting stuck on corners?

Box Colliders can catch on sharp corners. Switch to a Capsule Collider for your character — its rounded shape slides over corners more smoothly. You can also lower the character's Rigidbody Friction value to help it slide.

How do I make an object stop moving after a collision?

In your collision code, set the Rigidbody's velocity to zero: collision.rigidbody.velocity = Vector3.zero;. You can also freeze specific axes using the Freeze Position checkboxes on the Rigidbody, or change the Body Type to Kinematic so physics no longer affects it.