unity-physicscore2d-bodies

Guides creation, configuration, and lifecycle management of PhysicsBody entities in Unity PhysicsCore2D.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Working with Unity's PhysicsCore2D API requires choosing correct body types, configuring mass and sleep behavior, and avoiding the common WORM concurrency crash when mutating bodies during simulation callbacks. This Skill provides the patterns and code examples to handle PhysicsBody lifecycle correctly.

Core Features & Use Cases

  • Body Type Selection: Guidance on Static, Kinematic, and Dynamic bodies, including collision behavior between types and when to use each.
  • Mass and Shape Configuration: Automatic density-based mass, batched shape creation with deferred mass updates, and manual mass/inertia/center-of-mass overrides.
  • Lifecycle Safety: Owner key patterns, sleep management, transform sync to GameObjects, and the WORM rule for safely creating or destroying bodies around simulation callbacks.
  • Use Case: A developer building a 2D platformer uses this Skill to create a dynamic character body with FreezeRotation, lowered center of mass, and deferred bullet destruction inside contact callbacks.

Quick Start

Ask the AI to create a dynamic PhysicsBody in Unity PhysicsCore2D with a circle shape, frozen rotation, and safe destruction on collision.

Frequently Asked Questions about unity-physicscore2d-bodies

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

FAQPage Schema
How do I create a dynamic physics body in Unity PhysicsCore2D?

Start from PhysicsBodyDefinition.defaultDefinition, set type to PhysicsBody.BodyType.Dynamic along with position, velocity, and gravity scale, then call world.CreateBody(def). Add at least one shape with nonzero density so the body has collision area and mass.

What is the difference between Static, Kinematic, and Dynamic bodies in PhysicsCore2D?

Static bodies never move and only collide with Dynamic bodies, suiting level geometry. Kinematic bodies move via code-set velocity and also only collide with Dynamic bodies, suiting moving platforms. Dynamic bodies respond to forces and collide with everything.

Why does my PhysicsCore2D game crash when destroying a body in a collision callback?

PhysicsCore2D uses a Write-Once-Read-Many model that forbids creating or destroying bodies during simulation callbacks like IPreSolveCallback. Defer structural mutations to IContactCallback, which runs after the simulation step on the main thread.

How do I set custom mass or center of mass on a PhysicsBody?

Read body.massConfiguration, override the mass, rotationalInertia, and center fields, then assign it back. This manual mode overrides the automatic density-based computation, useful for fixed character weight or lowering the center of mass to prevent tipping.

How do I sync a PhysicsBody position to a Unity GameObject transform?

Sync in LateUpdate using PhysicsMath.ToPosition3D and PhysicsMath.ToRotationFast3D with the appropriate TransformPlane such as XY or XZ. PhysicsCore2D bodies are not attached to GameObjects, so manual per-frame synchronization is required.

Why does my dynamic PhysicsBody not move after creation?

The most common cause is forgetting to set the body type, since PhysicsBodyDefinition defaults to Static which never moves. Also verify the body has at least one shape with nonzero density, or use manual mass configuration to avoid zero-mass behavior.