/unity-dev:unity-physics-2dfrom unity-dev
Diagnoses 2D physics bugs in Unity: OnCollisionEnter2D failures, tunnelling, self-hit casts, one-way platforms, and editor-vs-build discrepancies.
Ships in unity-dev. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A PhysX rule renamed with a 2D suffix is usually wrong. A kinematic
Rigidbody2Dmoves under its velocity, a ray that starts inside a collider hits it, sleep is a timer, there are two collision-detection modes, and Z separates nothing. Almost nothing here throws. Work the ladder; do not translate what the 3D engine would do.
First match wins. Stop at the first cause you confirm and write the diagnosis.
| Symptom | Go to |
|---|---|
OnCollisionEnter2D / OnTriggerEnter2D never fires | §1 |
| A kinematic sentry walks through walls and reports nothing | §1 — full kinematic contacts |
| A bullet or a fast runner passes through a wall | §2 |
| A fast body skips a pickup or a hazard trigger | §2 — triggers are not swept |
| A ground check reports the caster itself, or a cast misses what is in its path | §3 |
| A click through the camera finds no 2D collider | §3 — a 3D ray against 2D shapes |
OnTriggerStay2D / OnCollisionStay2D ran, then went quiet | §4 — the body fell asleep |
A Rigidbody2D jitters; the runner stutters while the camera follows | §4 |
| The tilemap falls out of the scene on Play, or when a composite collider is added | reference/shapes-platforms-build.md §5 — the composite's body |
| The runner snags on flat ground, tile edges or seams | reference/shapes-platforms-build.md §5 |
| A body ends up inside a wall and stays there | reference/shapes-platforms-build.md §5 — outlines are hollow |
| The one-way platform blocks from below, or grips at the sides | reference/shapes-platforms-build.md §6 |
| Works in the editor, not in the build | reference/shapes-platforms-build.md §7 |
| Collisions changed after a respawn or a return to the pool | reference/shapes-platforms-build.md §7 — per-instance ignore pairs |
| Hurtboxes or hitboxes that follow a bone of a skinned character | reference/bone-colliders.md |
Connect to the Editor rather than reading files — unity-debug → reference/editor-control.md.
Rigidbody2D, Collider2D, Physics2D and messages ending in 2D are
this ladder; Rigidbody and Physics are unity-physics-3d; UnityEngine.LowLevelPhysics2D
(PhysicsWorld, PhysicsBody) is a third vocabulary. The stacks never see each other, and a
message from the wrong one is silent.Project Settings → Physics 2D → Layer Collision Matrix is not the 3D one.Physics2D.simulationMode. In SimulationMode2D.Script nothing moves until code calls
Physics2D.Simulate; a test that set it and never restored it freezes every later scene.Physics2D.SyncTransforms() once before querying. Physics2D.autoSyncTransforms is deprecated.Physics2D.Simulate() outside play mode: scripts without
[ExecuteAlways] receive no messages. Queries do work there, after a sync.Body types, the step and Physics2D.Simulate:
reference/bodies-and-simulation.md.
Work down. First match wins.
Rigidbody2D that is not Static. A collider with no body is on
the hidden static body; static × static never makes a contact.Rigidbody2D.simulated == false removes the body, its colliders and its joints: no
callbacks, no query hits, and the inspector looks right. So does a disabled collider, an
inactive parent, or a layer missing from Physics2D.simulationLayers.useFullKinematicContacts = true. With it the body gets OnCollisionEnter2D and
contact points and is still not pushed.isTrigger, the pair gets OnTrigger*2D and
never OnCollision*2D.a.CanContact(b) answers for the matrix and every layer override at once;
Physics2D.GetIgnoreCollision(a, b) for a per-instance ignore. Contact with no message is
Collider2D.callbackLayers.Rigidbody2D's, with the exact
signature: OnCollisionEnter2D(Collision2D), OnTriggerEnter2D(Collider2D).CompositeCollider2D loses its own isTrigger and material; the
composite's apply.| Pair | OnCollisionEnter2D (no trigger) | OnTriggerEnter2D (a trigger in the pair) |
|---|---|---|
| Dynamic × anything | Yes | Yes |
| Kinematic × Kinematic or Static | Only with useFullKinematicContacts | Yes |
| Static × Static, or no body on either side | Never | Never |
Layer schemes, overrides and the ignore calls:
reference/layers-and-matrix.md.
Rigidbody2D.collisionDetectionMode | Sweeps against |
|---|---|
CollisionDetectionMode2D.Discrete | Nothing — the body is tested where each step lands |
CollisionDetectionMode2D.Continuous | Every non-trigger collider in its path |
Two modes, not four. With no speculative mode, a hit reported before two shapes touch is a collider larger than its sprite.
Continuous on the fast body, not on the wall; reserve it for the runner and for
projectiles.Continuous does nothing for a Kinematic body and nothing for triggers. At 40 units/s a
body covers 0.8 units per 0.02 s step and steps over a thinner pickup trigger.Physics2D.CircleCast
or Rigidbody2D.Cast and stop at the first hit:
reference/queries-2d.md.fraction 0 with the normal
pointing back along the ray: Physics2D.queriesStartInColliders is true. A ground ray from
the runner's centre returns the runner. Use Collider2D.Cast or Rigidbody2D.Cast, which
ignore the caster, or mask its layer out. Leave the global alone.Physics2D.queriesHitTriggers is true, but an overload taking a ContactFilter2D also
needs filter.useTriggers, which is false in new ContactFilter2D(): one overload finds
the pickup, the other does not.minDepth / maxDepth compare the collider's Transform Z. Collisions ignore
Z, so a wall at Z 5 stops the runner and a depth-filtered cast misses it.Physics2D.GetRayIntersection(ray) takes it; under an orthographic
camera Physics2D.OverlapPoint(camera.ScreenToWorldPoint(p)) is enough.Every query, the list overloads, the filter fields and the start-inside table:
reference/queries-2d.md.
Physics2D.linearSleepTolerance (0.01) for
Physics2D.timeToSleep (0.5 s) sleeps, and OnCollisionStay2D / OnTriggerStay2D stop. For
a zone that must tick while something rests in it, set sleepMode = RigidbodySleepMode2D.NeverSleep on the one body, or count Enter and Exit. AddForce wakes
a sleeping body: a force that seems swallowed is too small, on a Kinematic body or a frozen axis.Rigidbody2D moves under linearVelocity. Gravity and forces are ignored;
velocity is not. A sentry that drifts after its patrol still has one.MovePosition is one step of velocity, a position write is a teleport. MovePosition
travels during the next step: a rider is carried, and a Dynamic body stops at a wall as §2
allows. Rigidbody2D.position and transform.position jump, with no velocity for a rider to
inherit. Move platforms and sentries as Kinematic bodies, in FixedUpdate.Rigidbody2D is rebuilt on the static body at every move and
carries nothing: the rider is left behind. Give it a Kinematic body.Time.fixedDeltaTime (0.02), the frame does not.
Set interpolation = RigidbodyInterpolation2D.Interpolate on any body the camera follows and
put the camera on one clock — unity-camera → reference/update-order-and-jitter.md. An
Animator or a script writing the body's own Transform each frame fights the step: animate a
child that holds the sprite.Time.timeScale == 0 stops the step; queries keep answering.Each of these in full, with Rigidbody2D.Slide:
reference/bodies-and-simulation.md.
reference/shapes-platforms-build.md§5 composites, hollow outlines and snagging seams; §6 effectors and one-way platforms; §7 what differs in a build, and per-instance ignore pairs after pooling. Same numbering there.
resources/CollisionDebugger2D.cs — attach to both suspected objects, drag each one's
collider into the other's other field, read the console, remove it when done.
| Console | Diagnosis |
|---|---|
Neither object logs [Setup] | The script is not on the objects you think it is |
[Setup] reports collider none, enabled False, simulated False or shapes 0 | §1 step 2, reference/shapes-platforms-build.md §5 |
[Pair] reports canContact False or ignored True | §1 step 5 |
[Setup] from both, [Pair] clean, no [Collision] / [Trigger] | §1 steps 1, 3, 4 |
[3D Collision] appears | 3D components in a 2D scene |
resources/Editor/Physics2DAudit.cs reads the open scene, changes nothing and prints one JSON
object — Tools/Unity Dev/Physics 2D/Audit Open Scene, or Physics2DAudit.Audit() from an eval.
It lists colliders that move with no body, layers that touch nothing, unmerged composite
children, triggers with no body, tilemap colliders with no composite and colliders with no shapes.
The player's own movement — ground check design, slopes, jump numbers, top-down and grid
motors — is unity-2d-controller. Painting tiles and a tile's collider type are
unity-tilemap; level layout and runtime tile data are unity-2d-level; cell occupancy and grid
pathfinding are unity-2d-grid. Sprite physics outlines are unity-2d-sprites; draw order is
unity-2d-rendering. A camera that stutters is unity-camera; pixel snapping is
unity-2d-pixel-perfect. Asserting that a recorded run never entered geometry is
unity-play-harness. PhysX — Rigidbody, Physics.Raycast, CharacterController — is
unity-physics-3d. Hit and hurt layers are unity-combat; pickup and switch triggers are
unity-interaction.
reference/bodies-and-simulation.md (opens in a new tab)reference/bone-colliders.md (opens in a new tab)reference/effectors-and-joints.md (opens in a new tab)reference/layers-and-matrix.md (opens in a new tab)reference/queries-2d.md (opens in a new tab)reference/shapes-platforms-build.md (opens in a new tab)reference/tilemap-colliders.md (opens in a new tab)resources/CollisionDebugger2D.cs (opens in a new tab)resources/Editor/Physics2DAudit.cs (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub tipoli5890/game-studio --plugin unity-dev51 skills in this plugin
/unity-2d-animationSkeletal 2D characters: PSB rig, bones and weights, sprite swaps, 2D IK (2D Animation package)./unity-2d-controllerMove a 2D character: platformer jump, slopes, coyote time, moving platforms, top-down movement./unity-2d-gridGrid tactics and tile puzzles, hex or square: move range, A* paths, line of sight, turns, undo./unity-2d-level2D level layout as data: Tiled/LDtk import, rooms, endless chunks, seeded levels, jump reachability.