Physics layers - configure what collides with what

Physics collisions on platformer
Physics layer choice in platformer
Physics collisions
Physics collisions
Physics names

I’m proud to announce new feature that enhances our physics: physics layers.

The idea is really simple: you can spread your objects (TCastleRigidBody) into multiple layers, and then configure which layer can collide with which. This way you can make certain things ignore other things. For example, maybe enemy_bullets should not hit other enemies or maybe enemies should not consider each other when walking (in some 2D games, it is normal that enemies can “pass through” each other).

There are really just 2 things to configure:

  1. At each rigid body, set the TCastleRigidBody.Layer to indicate the layer on which the body is.

    To help with this, you can add names and even longer descriptions to layers. Do this through Viewport.Items.PhysicsProperties.LayerNames. In the usual workflow, just click to configure LayerNames using “…​” button in the editor. The names and descriptions are only for the developer, to better document the layer meaning.

  2. Configure which layer collides with which using the checkboxes at Viewport.Items.PhysicsProperties.LayerCollisions. You can set them from code, or click on “…​” from CGE editor to configure them visually.

The simple usage example is in examples/physics/physics_3d_collisions_layers/. More involved example is in examples/platformer.

The documentation of this feature is part of the manual about physics.

1 Like