Note: This documentation is about writing C# scripts using the LowLevelPhysics2D API. To use 2D physics in the Unity Editor using components like the Rigidbody 2D component, refer to 2D physics instead.
In Unity, a collisionA collision occurs when the physics engine detects that the colliders of two GameObjects make contact or overlap, when at least one has a Rigidbody component and is in motion. More info
See in Glossary happens when two objects occupy the same physical space.
To detect collision between LowLevelPhysics2D 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 ColliderAn invisible shape that is used to handle physical collisions for an object. A collider doesn’t need to be exactly the same shape as the object’s mesh - a rough approximation is often more efficient and indistinguishable in gameplay. More info
See in Glossary 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.
In the LowLevelPhysics2D API, collisions are enabled by default.
How a shape reacts to collisions depends on its type:
For more information, refer to Configure collisions between LowLevelPhysics2D API objects.
To detect collisions and overlaps using callbacks or events, refer to Detect collisions between objects.
Unity uses layers to determine which objects collide with each other.
By default the following applies:
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 LowLevelPhysics2D API, you can use a different set of 64 layers, instead of the standard set of 32 GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary layers. For more information, refer to Use up to 64 layers.