Description
Version
- Phaser Version: 3.80.1
- Operating system: Windows, OSX
- Browser:
Description
The default mask that is set within the Body
class and the Collision
component only matches against collision categories that are equal to 1
. If setCollisionCategory()
or addCollidesWith()
are used on sprites within a physics group this causes the objects to no longer collide when checked against another physics group, even if the mask values would work in direct Sprite vs Sprite collision checks.
Example Test Code
I've posted an example that reproduces the issue and includes a potential fix over on JSBin and included the core game code below as well.
const blockA = this.add.sprite(200, 300, 'blockA');
const blockB = this.add.sprite(400, 300, 'blockB');
const blockC = this.add.sprite(600, 300, 'blockC');
const group1 = this.physics.add.group();
const group2 = this.physics.add.group();
group1.add(blockA);
group2.add(blockB);
group2.add(blockC);
const category1 = this.physics.nextCategory();
const category2 = this.physics.nextCategory();
blockA.body.setCollisionCategory(category1);
blockA.body.addCollidesWith(category2);
blockB.body.setCollisionCategory(category2);
blockB.body.addCollidesWith(category1);
blockC.body.setCollisionCategory(category2);
blockC.body.addCollidesWith(category1);
this.physics.add.collider(group1, group2);
Additional Information
I think the default collisionMask
should be changed to 2147483647
so that it will match against any collisionCategory
.
Also, there is added confusion when troubleshooting collision issues because the documentation for physics groups doesn't mention that they have a collision mask or collision category that can be set.