Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group vs Group collisions fail if child objects have non-default masks or categories because the default collisionMask only matches the category "1". #6764

Closed
codeimpossible opened this issue Mar 7, 2024 · 1 comment · May be fixed by jonesrussell/nishman#6
Assignees

Comments

@codeimpossible
Copy link

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.

@zekeatchan
Copy link
Collaborator

Hi @codeimpossible. Thanks for your suggested fix.

It has been pushed to the master branch and will be part of the next release. If you have time do test it out. Feel free to let us know if you encounter any issues or need further assistance.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants