Been wanting to understand collision masking for sometime and I can put it off no longer.
I've read and read and read through the API, Wiki & this topic
https://forum.orx-project.org/discussion/6340#Comment_6341 to full grasp how it works.
Is my understand correct as follows:
* Box 2D only allows 16 different "categories"
* You need to set up a flag for one object, and a checkmask for the other, and do the same in reverse of those two objects in order to have a collision.
So if I think in terms of binary, 0xFFFF is 65535 which is:
1111111111111111
Which is 16 binary digits, each representing a category.
So now I can define self flags & check masks to my objects like so:
[HeroBodyPart]
SelfFlags = 0000000000000001 ;should be hex, but to illustrate the point....
CheckMask = 0000000000000110
(checkmask essentially WallA/B & Enemy)
[WallA_BodyPart]
SelfFlags = 0000000000000010
CheckMask = 0000000000000101
(checkmask essentially Hero & Enemy)
[WallB_BodyPart]
SelfFlags = 0000000000000010
CheckMask = 0000000000000101
(checkmask essentially Hero & Enemy)
[EnemyBodyPart]
SelfFlags = 0000000000000100
CheckMask = 0000000000000011
(checkmask essentially WallA/B & Enemy)
So in the above, hero matches with wallA/B (also with enemy), but wall must also match with hero to create an actual collision.
I think that's the theory.. am I right?
I'll try it out and post back. Hopefully this might help with others who find this a little tricky.
Comments
if you put the config on body sections rather than bodypart sections, you're not going to get anywhere.
I've edited the above to illustrate that the configs go into bodypart sections.
https://forum.orx-project.org/discussion/6571#Comment_6575
Also, if you need to change the flags in game (as I needed, since after an arrow hit a monster or the ground it should no longer hit monsters):
Yep I noticed this discussed in Knolan's thread and I did try literals but they didn't work for me... I think maybe these are a orx 1.4 feature. I've been trying to get away with not admitting I haven't upgraded my project yet
Will do soon.. I'm just on too much of a roll.
Thanks for the full example there, Knolan, that's great.
As a side note, if you really want it you can use binary representation for any config numbers (including flags&masks) using the prefix 0b: