Version: Unity 6.7 Beta (6000.7)
Language : English
Introduction to collision in 2D Physics Core
Detect contact between 2D Physics Core objects

Configure collisions between 2D Physics Core objects

Set which 2D Physics Core objects collide with each other, using contact filters and layers.

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.

By default, the following applies:

  • Objects use GameObject layers, and all objects are on the built-in layer called Default.
  • Objects collide with objects on all other layers.
  • You can use up to 32 layers.

To change this behavior, do the following:

  1. Set 2D Physics Core to use its own set of 64 layers, instead of GameObject layers.
  2. Configure which layers objects are on, and set which layers each object collides with.

Note: To configure how a physics object reacts to a collision, for example how bouncy it is, use the Surface Material properties in the Definition section of its Physics Area component.

Set 2D Physics Core to use its own set of layers

Follow these steps:

  1. Create and assign a Physics Core Settings 2D asset. For more information, refer to Configure global 2D Physics Core settings.
  2. Go to Edit > Project Settings > Physics Core 2D > Settings.
  3. In the Global section, enable Use Physics Layers.

The Contact Filter properties now use the layers in the Layers section of the Settings window.

Use the Layers section to add, edit, or remove layers. For more information, refer to Physics Core 2D reference.

Change which objects collide

To set which objects an area collides with, follow these steps:

  1. Create the layers you need. For more information, refer to Physics Core 2D reference.
  2. Select a GameObject that has a Physics Area component.
  3. In the Inspector window, expand the Definition section of the Physics Area component, then expand Contact Filter.
  4. Set Categories to the layers you want the area to belong to, for example Default.
  5. Set Contacts to the layers you want the area to collide with, for example Nothing for no layers.

To use the same contact settings for several components, use a Physics Contact Filter asset. For more information, refer to Share properties across multiple 2D Physics Core components.

To set which objects an area collides with in a script, refer to the PhysicsShape.ContactFilter API.

Prevent objects passing through each other

Because physics objects move in steps, fast-moving objects can sometimes pass through other objects without activating a collision. This is called tunneling.

2D Physics Core automatically uses continuous collision detection to prevent tunneling when dynamic objects approach static objects. However, if a very fast-moving object still passes through another object, enable Fast Collisions Allowed on its Physics Pose component. Enabling this property can reduce performance. For more information, refer to Physics Pose component reference.

Additional resources

Introduction to collision in 2D Physics Core
Detect contact between 2D Physics Core objects