Physical System Configuration

    There exists two ways to configure the physics system, one is to configure it in the editor, and the other is to configure it in the code.

    The Project Settings -> Physical Configuration allows you to configure the related physics system.

    Programmatic configuration

    The physics system can be configured via . Some code examples are as follows:

    The physics configuration can also be reset through the PhysicsSystem.resetConfiguration interface, with the following code example:

    1. let conf = game.config.physics
    2. PhysicsSystem.instance.resetConfiguration(conf);

    For more API content, please check the PhysicsSystem interface please refer to: .

    Collision Matrix

    The collision matrix is a further wrapper around the function, which is used to initialize the groups and masks of physics elements.

    physics-collision

    By default the collision matrix has only one DEFAULT group, new groups do not collide with other groups by default.

    • Index represents the collision group value, which supports up to 32 bits, i.e. the value range is . Group values cannot be repeated.

    The figure shows the configuration of a collider group for a flying shooter game. As you can see from the figure, when a group is added, the panel appears with the names of the groups both horizontally and vertically. Let’s call the horizontal part Group and the vertical part Mask. Suppose we now make the following checkboxes:

    set-collider-config

    This configuration means that the group ENEMY_PLANE can collide with the groups ENEMY_BULLET and SELF_BULLET. Here the group ENEMY_BULLET and SELF_BULLET are the masks of the group ENEMY_PLANE. Similarly, for the group ENEMY_BULLET, ENEMY_PLANE is also its mask.

    Once the collision matrix is configured, you can add the RigidBody component to the object to be collided with and set the collision group Group.