unity-2d-physics
Unity 2D physics — Rigidbody2D body types, Collider2D shapes, joints, effectors, layer collision matrix, contact filters, IEEE physics gotchas in 2D, raycast/overlap APIs. USE WHEN: tuning Rigidbody2D movement, joint setups (hinge/spring/distance/ slider), one-way platforms, conveyor belts, area effects, layered collisions, raycast queries. DO NOT USE FOR: 3D physics (use `unity-physics-anim`); platformer character movement (use `unity-2d-gameplay`); tilemap collision (use `unity-2d-tilemap`).
What this skill does
# Unity 2D Physics
## Rigidbody2D body types
| Body Type | Behaviour |
|---|---|
| **Dynamic** | Moves under force/gravity/velocity. Most gameplay objects. |
| **Kinematic** | Moves only via `MovePosition`/`MoveRotation`. No automatic forces. Use for player controllers when you handle motion manually. |
| **Static** | Doesn't move. Optimised. Use for terrain, tilemaps. |
```csharp
[RequireComponent(typeof(Rigidbody2D))]
public class Push : MonoBehaviour {
private Rigidbody2D _rb;
void Awake() {
_rb = GetComponent<Rigidbody2D>();
_rb.interpolation = RigidbodyInterpolation2D.Interpolate;
_rb.collisionDetectionMode = CollisionDetectionMode2D.Continuous; // critical for fast movers
}
public void Push2D(Vector2 dir) => _rb.AddForce(dir * 10f, ForceMode2D.Impulse);
}
```
## Collider2D shapes
`BoxCollider2D`, `CircleCollider2D`, `CapsuleCollider2D`, `EdgeCollider2D` (open polyline), `PolygonCollider2D` (closed shape). Stick to primitives where possible — polygons with many vertices are expensive.
`CompositeCollider2D` merges multiple child colliders into a single optimized shape (standard for tilemap collision).
## Joints
| Joint | Use |
|---|---|
| **Hinge2D** | Doors, windmills, ragdoll limbs |
| **Distance2D** | Two bodies at fixed distance — chains, ropes (with multiple links) |
| **Spring2D** | Bouncy connections — suspension, jelly |
| **Slider2D** | Constrained linear motion — drawers, pistons |
| **Fixed2D** | Glue bodies together until break force |
| **Wheel2D** | Vehicle wheels (suspension + motor) |
| **Target2D** | Move toward a target with damping (mouse drag) |
| **Friction2D** | Dampen relative motion (handy on conveyor return paths) |
| **Relative2D** | Anchor at a relative offset |
## Effectors
Auto-applied behaviours on a collider:
| Effector | Effect |
|---|---|
| **PlatformEffector2D** | One-way platforms, flip-through detection |
| **AreaEffector2D** | Constant force inside the area (wind, water current) |
| **PointEffector2D** | Attract/repel from a point |
| **SurfaceEffector2D** | Conveyor belt — moves objects in contact |
| **BuoyancyEffector2D** | Water buoyancy + drag |
Tag the collider as `Used By Effector` and add the effector component on the same GameObject.
## Layer collision matrix
`Edit > Project Settings > Physics 2D > Layer Collision Matrix`. Cull pairs (`Player`/`Player`, `EnemyProjectile`/`Enemy`) — both correctness and perf.
## Contact filters & queries
```csharp
private static readonly Collider2D[] HitsBuffer = new Collider2D[16];
private ContactFilter2D _filter;
void Awake() {
_filter = new ContactFilter2D {
useLayerMask = true,
layerMask = LayerMask.GetMask("Enemy"),
useTriggers = false,
};
}
void Hit() {
int n = Physics2D.OverlapCircle(transform.position, 0.5f, _filter, HitsBuffer);
for (int i = 0; i < n; i++) HitsBuffer[i].GetComponent<IDamageable>()?.Damage(10);
}
```
Allocation-free `OverlapCircle/Box/Raycast` overloads avoid GC pressure in hot paths.
## 2D physics gotchas
- **Z position** affects rendering but NOT 2D physics (everything is at z=0 collision-wise).
- **Mass** matters for collision response; tweak via Rigidbody2D Mass (or Auto Mass = ON for density-based).
- **Continuous Collision Detection** — required for high-speed objects (bullets) to avoid tunneling.
- **Simulation Speed**: 50Hz default (FixedUpdate). Higher → smoother + heavier; 30Hz acceptable for casual.
- **Z-axis Job** — physics 2D doesn't run jobs by default; enable in Project Settings → Physics 2D > Use Multithreaded Simulation.
## Anti-patterns
| Anti-pattern | Fix |
|---|---|
| `transform.position` for Rigidbody2D objects | `MovePosition` / set `linearVelocity` in FixedUpdate |
| Polygon collider with hundreds of points | Decompose into primitives or composite |
| Discrete collision on bullets | Continuous CCD |
| Many per-frame `OverlapCircle` allocations | Use NonAlloc / ContactFilter2D overloads |
| Joints with default break force = infinity for breakable links | Set Break Force / Break Torque |
| Effector without `Used By Effector` flag | Tick `Used By Effector` on the collider |
## Production checklist
- [ ] Layer collision matrix culled
- [ ] Static colliders + composite for tilemap-like geometry
- [ ] Continuous detection on fast bodies
- [ ] Allocation-free physics queries in hot paths
- [ ] Joints have realistic break forces
- [ ] Physics 2D substep sufficient for target framerate
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.