Get started with 2D Physics Core
Create a 2D physics scene with a falling circle that lands on the ground, using 2D Physics Core components.
Read time 2 minutesLast updated 15 days ago
Understand how to create a simple scene with 2D Physics Core components, including using Physics Pose and Physics Area components to create a GameObject that reacts to physics, and a Physics Constraint component to connect two GameObjects together.
Install the package
To install the 2D Physics Core package, follow these steps:
- From the main menu, select Window > Package Manager to open the Package Manager window.
- In the Sources section, select Unity Registry.
- Select 2D Physics Core from the list of packages.
- Select Install.
Create a falling circle
To create a GameObject that falls under gravity, follow these steps:
- Create an empty GameObject.
- Select the GameObject, then in the window select Add Component, then Physics 2D (Core) > Physics Pose.Inspector
?
- Set to Dynamic.Body Type
?
- Select Add Component again, then Physics 2D (Core) > Physics Area Circle.
- In the Transform component, set the Y value of Position to , so the GameObject starts higher up with room to fall.
2 - Enter Play mode. The GameObject falls under gravity.
Create ground
To create a static ground for the circle to land on, follow these steps:
-
Create an empty GameObject.
-
Select the GameObject, then in the Inspector window select Add Component, then Physics 2D (Core) > Physics Pose.Leave Body Type set to Static, so the ground doesn't move.
-
Select Add Component again, then Physics 2D (Core) > Physics Area Path.
-
In theview, edit the path's vertices to form a flat line underneath where the circle will land. For more information, refer to Visualize and edit 2D Physics Core scenes.Scene
?
-
Enter Play mode. The circle falls and lands on the ground.
Create a connection between two objects
To connect objects together, add a Physics Constraint component. Follow these steps:
-
Select the circle GameObject.
-
In the Inspector window, select Add Component, then Physics 2D (Core) > Physics Constraint Distance.In the Physics Constraint Distance component, Unity automatically sets Pose A Source to the circle GameObject.
-
Drag the ground GameObject into the Pose B Target field.
-
In the Definition section, set Distance to. This sets the minimum distance between the two GameObjects.
3 -
Enter Play mode. The circle stops falling once it's 3 meters from the ground.