Version: Unity 6.7 Beta (6000.7)
Language : English
Create complex shapes with 2D Physics Core
Visualize and edit 2D Physics Core scenes

Merge 2D Physics Core shapes

To merge multiple physics shapes into one shape, for example to create a car with a body and two wheels, use one of the following approaches:

  • Create a group of primitives
  • Merge a group of custom shapes

Note: This documentation is about using Pose, Area, and Constraint components. To use 2D physics in the Unity Editor using components like the Rigidbody 2D component, refer to 2D physics instead.

Merge a group of primitives

To create a merged shape from primitives, add a Physics Area Composite component and build up its layers.

Add a Physics Area Composite component

Follow these steps:

  1. Select a GameObject in the Hierarchy window, or create an empty GameObject.
  2. Add a Physics Area Composite component to a GameObject.
  3. Set Output to Segments for a merged outline shape, or Polygons for a merged filled shape.

Add a single shape

Follow these steps:

  1. In the Geometry section of the Inspector window, select Add Geometry.
  2. In the layer Unity adds, set Geometry to Circle, Capsule, or Polygon.
  3. To set the position of the shape relative to the parent GameObject, expand Transformation in that layer and set its properties.

To add every area attached to an existing Physics Pose component instead, select Add Pose. Unity references the Area components attached to the Physics Pose component, rather than copying them. The Physics Pose component goes into composite mode. Composite mode stops the Physics Pose component using its own shapes, so that Unity doesn’t simulate or draw the same shapes twice.

For the full list of properties, refer to Physics Area Composite component reference.

Merge a group of custom shapes

To merge custom shapes, use a contour group. For example, to create an arbitrary silhouette, a shape with a hole in it, or several disconnected pieces in one area.

Follow these steps:

  1. After you select Add Geometry, set Geometry to Contour Group.

    By default, a contour group contains one contour, the vertices for a single square.

  2. To add another vertex to the contour, select Add Vertex.

  3. Select Add Contour to add another shape.

You can edit the vertices in the Inspector window, or edit contour vertices directly in the Scene view. For more information, refer to Visualize and edit 2D Physics Core scenes.

Control how each layer combines

To control how each layer combines with the previous layers in an outline or filled shape, expand Composite in the layer section, then select a value for Operation.

The options are:

  • OR: Adds the shape.
  • AND: Keeps only the areas where the new shape and the existing combined shape overlap.
  • NOT: Subtracts the new shape from the existing combined shape.
  • XOR: Removes the overlapping areas, but keeps the non-overlapping areas.

Set which side of a layer faces out

To set which side of the merged layer faces out, use the Winding property.

  • If you set Output to Polygons, set Winding to CW (clockwise) for a solid shape, or CCW (counter-clockwise) for a hole.
  • If you set Output to Segments, set Winding to CW (clockwise) for collision on the right side of the outline, or CCW (counter-clockwise) for collision on the left side of the outline.

Additional resources

Create complex shapes with 2D Physics Core
Visualize and edit 2D Physics Core scenes