# Pixeldex · Unity 2D Platformer Starter

A drop-in Unity 2D platformer player controller with **coyote time, jump buffer, and variable jump height** — the three "feel" details that separate a playable platformer from a frustrating one. Tested on Unity 2022.3 LTS.

License: **CC0** (public domain). Use it however you like, no attribution required.
Source: https://pixeldex.app/prompts/unity-2d-platformer-coyote-time

---

## What's in this folder

| File | Where to put it | What it does |
|---|---|---|
| `PlatformerController.cs` | `Assets/Scripts/` | The player controller. Attach to your Player GameObject. |
| `PixeldexPlatformerSetup.cs` | `Assets/Editor/` | Editor utility. Adds a "Pixeldex → Spawn Platformer Player" menu that creates a fully-wired Player in the scene with one click. |

The Setup script is **optional**. If you'd rather wire it up by hand, see "Manual setup" below.

---

## Fastest path (~30 seconds)

1. Create folders `Assets/Scripts/` and `Assets/Editor/` if they don't exist.
2. Drop `PlatformerController.cs` into `Assets/Scripts/`.
3. Drop `PixeldexPlatformerSetup.cs` into `Assets/Editor/`.
4. Wait a moment for Unity to compile (you'll see a brief loading bar).
5. In the Unity menu bar, click **Pixeldex → Spawn Platformer Player** (or press `Cmd+Shift+P` / `Ctrl+Shift+P`).
6. A pink Player GameObject appears in the scene with all components wired up.
7. Add some ground (Tilemap or any GameObject on the "Ground" layer with a Collider2D).
8. Press Play. WASD or arrow keys to move, Space to jump.

---

## Manual setup (~3 minutes)

If you'd rather not use the Editor utility:

1. Drop `PlatformerController.cs` into `Assets/Scripts/`.
2. In your scene, create an empty GameObject named **Player**.
3. Add components: `Rigidbody 2D`, `Box Collider 2D`, `Platformer Controller`.
4. On the Rigidbody 2D: set Body Type to **Dynamic**, Gravity Scale to **3**, check **Freeze Rotation Z**, set Interpolation to **Interpolate**.
5. As a child of Player, create an empty GameObject named **GroundCheck**. Position it at `(0, -0.85, 0)` relative to the player (i.e. just below the collider).
6. In the Project Settings → Tags and Layers, add a new layer called **Ground**.
7. Set any ground GameObjects in your scene to the Ground layer.
8. On the PlatformerController component:
   - Drag the **GroundCheck** child into the `Ground Check` field.
   - Set the `Ground Layer` mask to `Ground`.
9. Add a Sprite Renderer to the player so it's visible.
10. Press Play.

---

## Tuning

All knobs are SerializeFields you can adjust in the Inspector at runtime:

| Field | Default | What it does |
|---|---|---|
| `speed` | 7 | Horizontal speed in units/sec |
| `moveSmoothing` | 0.06 | Lower = snappier, higher = floatier movement |
| `jumpForce` | 14 | Initial upward velocity on jump |
| `coyoteTime` | 0.1 | Grace window after walking off a ledge |
| `jumpBufferTime` | 0.1 | Lookback window for jump pressed just before landing |
| `jumpCutMultiplier` | 0.5 | How much velocity to cut when jump is released early |
| `groundCheckRadius` | 0.15 | Size of the ground-check circle |

If movement feels stiff, lower `moveSmoothing` (try 0.03). If it feels floaty, raise the Rigidbody2D's Gravity Scale to 4.

---

## Common gotchas

**Character jitters when moving.** Set Rigidbody2D Interpolation to `Interpolate`. The Setup utility does this for you.

**Can't jump at all.** Your GroundCheck is probably overlapping the ground at rest. The default offset of `-0.85` works for a 1.6-unit-tall collider; adjust if your sprite is taller or shorter.

**Falls through tiles.** The Tilemap needs a `Tilemap Collider 2D` component, then add a `Composite Collider 2D` (auto-adds Rigidbody2D — set its Body Type to `Static`), and check **Used By Composite** on the Tilemap Collider.

---

## Where this came from

This starter is the pre-tested output of [Pixeldex's coyote-time platformer prompt](https://pixeldex.app/prompts/unity-2d-platformer-coyote-time). If you want to regenerate it yourself with Claude (e.g. to customize the constraints), the source prompt is on that page.

If you want the full picture — how this controller fits with tilemaps, enemies, coins, sound, and a final itch.io upload — follow [the platformer walkthrough](https://pixeldex.app/walkthroughs/build-2d-platformer-with-claude-in-a-weekend).

---

If you ship a game with this, a link to https://pixeldex.app in your itch description helps the next solo dev find this stuff. Not required.
