unity-physicscore2d-destruction-patterns

Implements destructible object patterns in Unity PhysicsCore2D including slicing, fragmenting, and sprite destruction.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Designing destructible objects in Unity's PhysicsCore2D API requires choosing between slicing, fragmenting, sprite destruction, and pre-fractured approaches, each with different performance and gameplay trade-offs. This Skill provides high-level design guidance plus complete worked C# examples so you can pick and implement the right destruction pattern without starting from scratch.

Core Features & Use Cases

  • Destruction Pattern Guidance: Compares slicing, fragmenting, sprite destruction, pre-fractured objects, and dynamic mesh splitting with implementation steps for each.
  • Worked Code Examples: Includes three complete MonoBehaviour examples demonstrating PhysicsDestructor.Slice, PhysicsDestructor.Fragment with masks and seed points, and island-splitting with static/dynamic remainder classification.
  • Performance & Gameplay Advice: Covers fragment pooling, debris cleanup, body-count budgeting, explosion impulses, and material-based break behavior.
  • Use Case: You are building a top-down shooter where projectiles break walls into debris. Use the FragmentingPattern example to fragment a destructible body on contact, rebuild the unbroken remainder, spawn debris bodies via CreateBodyBatch, and apply an explosion impulse.

Quick Start

Ask the AI to design a destructible object system for your Unity PhysicsCore2D game, for example by requesting a fragmentation-on-impact pattern using PhysicsDestructor with debris cleanup.

Frequently Asked Questions about unity-physicscore2d-destruction-patterns

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

FAQPage Schema
How do I fragment a physics body on impact in Unity PhysicsCore2D?

Use PhysicsDestructor.Fragment with a target FragmentGeometry, a mask geometry limiting the affected area, and random seed points around the hit position. Destroy the original body, then rebuild the unbroken remainder as one body and the broken pieces as a batch of dynamic debris bodies via CreateBodyBatch.

How do I slice a 2D physics shape along a line in Unity?

Call PhysicsDestructor.Slice with the target polygon geometry, a ray origin, and a translation vector. The result contains leftGeometry and rightGeometry arrays; create a new body for each side and apply a perpendicular separation velocity to push the halves apart.

What is the difference between slicing and fragmenting in PhysicsCore2D?

Slicing cuts geometry along a single line into two pieces, while fragmenting breaks geometry into many pieces using seed points within a mask region. Slicing suits clean cuts like sword slashes; fragmenting suits explosions and impact shattering.

How do I keep part of a destructible object static after destruction?

Split the unbroken remainder into geometry islands using fragmentResults.unbrokenGeometryIslands, then test each island against a virtual ground line with geometry.Intersect. Islands touching the ground become static bodies; the rest become dynamic and fall.

How do I limit performance cost of physics destruction debris?

Cap the fragment count, check world.counters.bodyCount against a maximum before slicing, use CreateBodyBatch for debris, and destroy debris on contact with ground via contact callbacks. Pre-fractured objects with weak joints are cheaper than runtime slicing.