Version: Unity 6.7 Alpha (6000.7)
Language : English
Collisions and interactions in the Physics Core 2D API
Configure collisions between Physics Core 2D API objects

Introduction to collision in the Physics Core 2D API

Note: This documentation is about writing C# scripts using the Unity.U2D.Physics API. To use 2D physics in the Unity Editor using components like the Rigidbody 2D component, refer to 2D physics instead.

In Unity, a collision happens when two objects occupy the same physical space.

To detect collision between Physics Core 2D API objects, Unity uses the PhysicsShape objects attached to the PhysicsBody. The shape defines the physics body for the purposes of physical collisions. The shape is similar to the Collider 2D component in the regular 2D physics system.

Shapes don’t need to be the same shape as the body, and you can add multiple shapes to one body.

For more information about adding a shape, refer to Create a physics object.

Collision types

In the Physics Core 2D API, collisions are enabled by default.

How a shape reacts to collisions depends on its type:

  • Collider: The shape can’t enter other objects. When the shape makes contact with another shape, it reports a contact event. This is the default.
  • Trigger: The shape goes through other objects. When the shape enters another shape, it reports a trigger event.

For more information, refer to Configure collisions between Physics Core 2D API objects.

To detect collisions and overlaps using callbacks or events, refer to Detect collisions between objects.

Collision layers

Unity uses layers to determine which objects collide with each other.

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.

To change this behavior, change the layers that objects are on, and the layers they collide with. For more information, refer to Configure collisions between 2D physics objects.

In the Physics Core 2D API, you can use a different set of 64 layers, instead of the standard set of 32 GameObject layers. For more information, refer to Use up to 64 layers.

Additional resources

Collisions and interactions in the Physics Core 2D API
Configure collisions between Physics Core 2D API objects