IN THIS ARTICLE
PhysX Collision Groups
Collision groups act as masks for collision layers. You can specify which collision layers are part of a collision group. A collision layer can be included in multiple collision groups. Each PhysX collider component can interact with one collision group. The collider can interact with any collider assigned to a collision layer included in the selected collision group.
Important:Colliders interact if their collision layers are in each other’s collision group. If one collision layer is not present in the other layer’s collision group, the colliders don’t interact.
Create a collision group
In O3DE Editor, from the Tools menu, choose PhysX Configuration.
Choose the Collision Filtering tab.
Click the Groups button to view the collision groups list. The available collision layers appear as columns.
Click Add, and then enter the name of the group into the text box.
Check the checkbox in the collision layer column to include the collision layer in the collision group. Clear the checkbox to exclude the collision layer from the collision group.
Collision group assignment
In O3DE Editor, select an entity with a PhysX Collider component you’d like to assign a collision group.
In the PhysX Collider component, from the Collides With property, choose one of the available collision groups from the drop-down list.
Example collision group configuration
The following example defines Player, Enemy, Bullet, and Terrain layers. These collision layers are categorized into the following collision groups:
- PlayerBullet - Collides with Enemy and Terrain.
- EnemyBullet - Collides with Player and Terrain.
- TerrainCollision - Collides with Player, Enemy, Bullet, and Terrain.
- PlayerCollision - Collides with Enemy, Bullet, and Terrain.
A bullet fired by the player has the following layer and group:
- Layer: Bullet
- Group: PlayerBullet
A bullet fired by the enemy has the following layer and group:
- Layer: Bullet
- Group: EnemyBullet
Note:You don’t have to define an “enemy bullet” or a “player bullet” layer. Instead, define a single Bullet layer and create separate collision groups to specify the objects that it collides with.