-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
Version
Phaser Version: 3.87.0
Operating system: Windows 11
Browser: Chrome 109.0.5414.120
Description
I am currently testing the Arcade Physics collision categories, as I can see that they exist not only in Matter but also in Arcade. However, they do not seem to work as expected.
Here’s the proof that collision categories exist in Arcade:
Documentation
Collision.js Reference
In my test, I have 4 types of collision objects that can collide with one another:
this.categories = {
playerMelee: 1, // 2^0 -> 0b0001
playerRanged: 2, // 2^1 -> 0b0010
enemyMelee: 4, // 2^2 -> 0b0100
enemyRanged: 8 // 2^3 -> 0b1000
};
I set each object’s body to the respective category:
container.body.setCollisionCategory(categories.playerMelee);
container.body.setCollidesWith([categories.enemyRanged, categories.playerRanged, categories.enemyMelee]);
Then I add colliders with this.physics.add.collider for each group separately.
At a certain point, I want to disable one of the collision groups using:
this.playerRanged1.body.removeCollidesWith(this.categories.playerMelee);
However, this does not work. The object continues to collide.
If I switch to Matter Physics, this functionality works as expected. Since my game is simple and I don’t need Matter's complexity, I prefer to use Arcade Physics. I suspect this is a bug specific to Arcade Physics.
Example Test Code
Here’s my sandbox test. Drag the objects around and check the logs:
Sandbox Test Link
Additional Information
The logs demonstrate that the collision categories are not being updated when calling removeCollidesWith. This suggests a potential issue with the implementation of Arcade Physics collision categories.