Configure collisions between 2D Physics Core objects
Set which 2D Physics Core objects collide with each other, using contact filters and layers.
Read time 2 minutesLast updated 14 days ago
Set which 2D Physics Core objects collide with each other, using contact filters and layers.
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:
- Set 2D Physics Core to use its own set of 64 layers, instead of GameObject layers.
- Configure which layers objects are on, and set which layers each object collides with.
Set 2D Physics Core to use its own set of layers
Follow these steps:
- Create and assign a Physics Core Settings 2D asset. For more information, refer to Configure global 2D Physics Core settings.
- Go to Edit > > Physics Core 2D > Settings.Project Settings
?
- 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:
- Create the layers you need. For more information, refer to Physics Core 2D reference.
- Select a GameObject that has a Physics Area component.
- In the window, expand the Definition section of the Physics Area component, then expand Contact Filter.Inspector
?
- Set Categories to the layers you want the area to belong to, for example Default.
- 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 API.
PhysicsShape.ContactFilterPrevent 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.