-
Notifications
You must be signed in to change notification settings - Fork 437
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
Physics fixture/shape :setMask bits are inverted in love compared to box2d #2072
Comments
Do we still want the behavior to keep Categories number as target (1 to 16) or their integer values 2^category_number ? |
i very strongly concur with OP here. flags/masks being inverted is a confusing footgun and makes no sense in light of the behavior of flags/masks in box2d itself |
This needs to be fixed to match Box2D specs. It caused me trouble and wasted testing time until I found this open issue. |
Right now I'm inclined to not change anything until we do a deeper rework of shape categories, because of this comment I left in the PR:
The real issue is that the box2D C API's bit mask doesn't translate well to Lua which doesn't have idiomatic bit masks in the same manner. I'd like to do a better high level API (possibly with an option to drop down to actual bit masks) instead, in the future. |
Also, just to clarify, while love.physics uses Box2D (2 currently, not 3) under the hood, it's not necessarily a bug if a love.physics API behaves differently from Box2D. Often it's just a different API design choice. |
As a user I found Love2D's inverted Box2d physics masking to be unfriendly in practice, with unexpected results, despite the stated intention to make things simpler. I suspect that they didn't test many use cases of colliding different bodies with multiple categories and different collision rules. |
Currently a fixture/shape needs to have in its mask every category that it doesn't want to collide with, which is the opposite of how it works in box2d
fixture:getMask says "Returns which categories this fixture should NOT collide with. "
https://love2d.org/wiki/Fixture:getMask
the box2d documentation says "The categoryBits flag can be thought of as the fixture saying 'I am a ...', and the maskBits is like saying 'I will collide with a ...'."
https://www.iforce2d.net/b2dtut/collision-filtering
This is awkward for a few reasons:
the inversion that love2d does can be seen here and on the corresponding functions in Fixture.cpp:
love/src/modules/physics/box2d/Shape.cpp
Line 281 in d576692
I'm suggesting that in love 12 the API be simplified to do the same thing as the corresponding box2d functionality. If appropriate the functions could be renamed to "setCollisionMask" from "setMask" for backwards compatibility and to make it clearer that the mask says which things an object will collide with.
The text was updated successfully, but these errors were encountered: