# 2. Physics 2D - Colliders, Composites and Materials
Part of [[Physics 2D]]. Previous: [[1. Physics 2D Rigidbody2D and Body Types]]. Next: [[3. Physics 2D Queries ContactFilter2D and Layers]]. 3D counterpart: [[2. Colliders and Physics Materials]].
> [!note] Verification status
> Component names and Physics Material 2D properties from the 6000.5 Manual; `Collider2D.compositeOperation`, `CompositeCollider2D` and `PhysicsMaterial2D` pages exist in the 6000.5 Scripting Reference (checked 2026-11-07). **Code not compiled in Unity.**
## 2.1 Collider 2D types
| Collider | Shape | Typical use | Cost note |
|---|---|---|---|
| Circle Collider 2D | circle | balls, coins, round enemies | cheapest |
| Box Collider 2D | box (optional edge radius) | crates, tiles, most props | cheap; edge radius rounds corners so characters don't snag |
| Capsule Collider 2D | capsule | **characters** | rounded bottom slides over tile seams |
| Polygon Collider 2D | convex pieces auto-generated from a sprite outline | irregular props | can decompose into many polygons; keep vertex counts low |
| Edge Collider 2D | open polyline | terrain lines, one-sided ground | no inside - things can end up on the wrong side if they tunnel |
| Custom Collider 2D | shapes you supply from script (`PhysicsShapeGroup2D`) | procedural geometry | advanced |
| Composite Collider 2D | merges other colliders into one outline or polygon set | tilemaps, modular level kits | huge win for level geometry |
## 2.2 Composite colliders (the 2D gray-box superpower)
A tilemap of 400 Box colliders produces 400 shapes with 400 internal seams. Characters catch on seams ("ghost collisions"). A **Composite Collider 2D** merges them into one outline.
Steps (Unity 6 workflow):
1. Create a Tilemap (see [[Tilemaps and Tilesets]]) and paint a gray-box level.
2. Add **Tilemap Collider 2D** to the Tilemap.
3. On the Tilemap Collider 2D set **Composite Operation** to **Merge**. (Unity 6 replaced the old "Used By Composite" checkbox with the `Collider2D.compositeOperation` setting, which also offers other boolean operations.)
4. Add **Composite Collider 2D**. Unity adds a **Rigidbody 2D**; set its Body Type to **Static**.
5. On the Composite Collider 2D pick **Geometry Type**:
- **Outlines** - hollow edge loops. Best for ground characters walk on: no internal seams.
- **Polygons** - solid. Use when you need Overlap queries to detect "inside the wall" or when Dynamic bodies might tunnel.
6. Play with a capsule character - seam snags vanish.
> [!tip] Teaching point
> Rogers' "Gray Matters" (Level 9, [[Level Up! (Review)]]) - with Tilemap + Composite you can iterate a level layout in minutes and the collision is always exactly what you see. That's the "if it looks like the player can go there, they should be able to" rule enforced by tooling.
## 2.3 Physics Material 2D
`PhysicsMaterial2D` (Assets > Create > 2D > Physics Material 2D) has **Friction** (0-1), **Bounciness** (0-1), and in 6000.5 **Friction Combine** (default Mean) and **Bounce Combine** (default Maximum) with Average / Mean / Multiply / Minimum / Maximum options. Unlike 3D's `PhysicsMaterial` there is a single friction value (no static vs dynamic split).
Assign it on a Collider2D (per-shape) or on the Rigidbody2D (`sharedMaterial`, applied to all attached colliders).
Recipe set for a platformer:
| Material | Friction | Bounciness | On |
|---|---|---|---|
| `NoFriction` | 0 | 0 | Player capsule (try Friction Combine = Minimum; verify how the two colliders' combine modes resolve) - stops "sticking" to walls when pressing into them mid-air |
| `Ground` | 0.4 | 0 | Default level geometry |
| `Ice` | 0.02 | 0 | Slippery hazard tiles |
| `Bouncy` | 0.2 | 0.9 | Trampolines (or use an effector, Part 4) |
## 2.4 Swapping materials at runtime
```csharp
using UnityEngine;
/// Makes a surface temporarily icy (e.g. after a freeze spell). Works on any Collider2D.
[RequireComponent(typeof(Collider2D))]
public class SurfaceMaterialSwapper2D : MonoBehaviour
{
[SerializeField] PhysicsMaterial2D iceMaterial;
[SerializeField] float duration = 5f;
Collider2D _col;
PhysicsMaterial2D _original;
float _until;
void Awake()
{
_col = GetComponent<Collider2D>();
_original = _col.sharedMaterial;
}
public void Freeze()
{
_col.sharedMaterial = iceMaterial;
_until = Time.time + duration;
enabled = true;
}
void Update()
{
if (Time.time >= _until)
{
_col.sharedMaterial = _original;
enabled = false;
}
}
}
```
> [!warning] Code not compiled in Unity
> Not compiled or play-tested. Bodies already in contact may keep the previous friction until the contact is re-evaluated; test with resting bodies.
## 2.5 Collider gotchas
- **Offset vs Transform:** move colliders with `offset`, not by nesting under scaled children. A Circle Collider 2D cannot become an ellipse, so non-uniform scale on a parent is silently ignored on one axis - the collision no longer matches the sprite.
- **Edge radius** on Box Collider 2D adds a rounded skin; the visual sprite edge and the collision edge then differ by that radius. Match it in your metrics.
- **Triggers** (`isTrigger`) produce `OnTriggerEnter2D` and no response. Queries skip them unless `Physics2D.queriesHitTriggers` or the ContactFilter2D says otherwise (Part 3).
## Docs
- Collider 2D (Manual): https://docs.unity.com/en-us/engine/6000.5/manual/unity2d/2d-physics/collider-2d
- Composite Collider 2D: https://docs.unity.com/en-us/engine/6000.5/manual/unity2d/2d-physics/collider-2d/composite-collider-2d
- Combine colliders: https://docs.unity.com/en-us/engine/6000.5/manual/unity2d/2d-physics/collider-2d/composite-collider-2d/combine-colliders-composite-collider-2d
- `Collider2D.compositeOperation`: https://docs.unity3d.com/6000.5/Documentation/ScriptReference/Collider2D-compositeOperation.html
- `CompositeCollider2D`: https://docs.unity3d.com/6000.5/Documentation/ScriptReference/CompositeCollider2D.html
- Physics Material 2D reference: https://docs.unity.com/en-us/engine/6000.5/manual/unity2d/2d-physics/physics-material-2d-reference
- `PhysicsMaterial2D`: https://docs.unity3d.com/6000.5/Documentation/ScriptReference/PhysicsMaterial2D.html