0
\$\begingroup\$

In the below code, I've created a mask value for the MASK_bullet. Which ~CATEGORY_BULLET cannot collide with bullet, CATEGORY_ENEMY can collide with bullet and so on. Now the problem is, it is not behaving the way as expected.

public static final short CATEGORY_ENEMY = 0x0002;
public static final short CATEGORY_MAP_OBJECT = 0x0008;
public static final short CATEGORY_BULLET = 0x00032;

public static final short MASK_BULLET = ~CATEGORY_BULLET | CATEGORY_ENEMY | CATEGORY_MAP_OBJECT;

How I set the category and mask.

FixtureDef fixtureDef = new FixtureDef();
fixtureDef.filter.categoryBits = CATEGORY_BULLET;
fixtureDef.filter.maskBits = MASK_BULLET;
\$\endgroup\$
6
  • \$\begingroup\$ ~CATEGORY_BULLET is 0b11110111, or-ing that with CATEGORY_ENEMY (0b01000000) doesn't do anything. The ~ operator is bitwise not, i.e. change 1 to 0 and vice versa. \$\endgroup\$
    – Elva
    Aug 1, 2016 at 14:53
  • \$\begingroup\$ I wrote up a small guide for another question: gamedev.stackexchange.com/a/58165/8119 \$\endgroup\$ Aug 1, 2016 at 15:27
  • \$\begingroup\$ Potential duplicate? \$\endgroup\$
    – user35344
    Aug 1, 2016 at 15:53
  • \$\begingroup\$ I didn't vote to close because while the same answer works for both questions, the question its self is still not quite the same. \$\endgroup\$ Aug 1, 2016 at 23:51
  • \$\begingroup\$ I don't think its the same @ClassicThunder \$\endgroup\$
    – ronscript
    Aug 2, 2016 at 5:14

0

You must log in to answer this question.

Browse other questions tagged .