unity-physicscore2d-shapes-advanced

Implements chain shapes, compound bodies, rounded polygons, and runtime geometry mutation in Unity PhysicsCore2D.

735|105|Updated Mar 4, 2017
One-click install
npx skills add https://github.com/Unity-Technologies/PhysicsExamples2D --skill unity-physicscore2d-shapes-advanced
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unity-physicscore2d-shapes-advanced
Source: https://github.com/Unity-Technologies/PhysicsExamples2D/tree/main/.claude/skills/unity-physicscore2d-shapes-advanced
Command: npx skills add https://github.com/Unity-Technologies/PhysicsExamples2D --skill unity-physicscore2d-shapes-advanced

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Working with Unity's PhysicsCore2D API beyond basic circles and boxes requires knowing non-obvious ownership rules, mutation paths, and validation discipline for chains, compound shapes, and runtime geometry edits. This Skill provides expert guidance and runnable C# examples so you avoid pitfalls like invalid polygon hulls, ghost-vertex stitching errors, and unnecessary destroy/recreate churn.

Core Features & Use Cases

  • Chain Shapes: Build terrain and boundaries with PhysicsChain.Create or standalone ChainSegmentGeometry.CreateSegments, including ghost-vertex stitching and in-place segment mutation via chainSegmentGeometry and PhysicsChain.UpdateVertices.
  • Compound & Rounded Shapes: Attach multiple shapes to one body, create rounded polygons via Minkowski radius offsets, and approximate ellipses with many-sided polygons.
  • Runtime Geometry Modification: Mutate PolygonGeometry in place with the manual write + Validate() pattern, swap shape geometry via type-specific setters, and split fragmented bodies into geometry islands with unbrokenGeometryIslands.
  • Use Case: You are building a destructible-terrain game in Unity 6000.5 and need to fragment a column, keep islands touching the ground static, and turn the rest into dynamic debris bodies.

Quick Start

Ask the assistant to show how to create a chain-shape terrain with PhysicsChain in Unity PhysicsCore2D and how to safely modify a polygon's vertices at runtime.

Frequently Asked Questions about unity-physicscore2d-shapes-advanced

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a chain shape for terrain in Unity PhysicsCore2D?

Use PhysicsChain.Create with a ChainGeometry built from your vertex list, or call body.CreateChain(chainGeometry, chainDefinition). The chain owns its segments and stitches ghost vertices automatically, with isLoop controlling closed loops.

What is the difference between PhysicsChain and ChainSegmentGeometry.CreateSegments?

PhysicsChain.Create creates an owned chain whose segments can only be destroyed together via PhysicsChain.Destroy. ChainSegmentGeometry.CreateSegments returns unowned geometries you attach as individual shapes, allowing per-segment destruction and mixing with hand-built segments.

How do I modify polygon vertices at runtime without errors in PhysicsCore2D?

Write vertices directly into the PolygonGeometry struct, set count, then call Validate() and check isValid before assigning it to a shape. This avoids the engine error that PolygonGeometry.Create logs on degenerate input and skips span ceremony in Burst jobs.

Can I update chain segment endpoints without destroying the shape?

Yes, in Unity 6000.5.0b9+ assign a new ChainSegmentGeometry to shape.chainSegmentGeometry, which preserves contact state. For owned chains, PhysicsChain.UpdateVertices updates all segments but requires matching vertex count and isLoop.

How do I handle geometry islands after fragmenting a destructible body?

Use PhysicsDestructor.Fragment and iterate fragmentResults.unbrokenGeometryIslands, creating a body per island. Test each island against a virtual ground segment with Intersect to decide whether it stays static or becomes dynamic debris.

When should I use compound shapes instead of multiple bodies with joints?

Use compound shapes when multiple collision regions must move rigidly together, such as character capsules with ground sensors or vehicle bodies with wheels. They share one PhysicsBody, allow per-shape materials, and are cheaper than jointed bodies.