I think people need to understand this to use it properly.
Whenever you create any physics body these three must need to be set setCategoryBitmask
, setCollisionBitmask
, setContactTestBitmask
, if any one is missing without initialize then it will not give you desire outout.
please dont use 'true', 'false' or '0' '1'
, it will make you difficult to understand.
Also dont set different collision mask for CATEGORY & COLLISION, use single mask per object, like below.
#define COL_MASK_BLANK 0x00000000
#define COL_MASK_PLAYER 0x00000001
#define COL_MASK_WEAPON 0x00000002
#define COL_MASK_ENEMY 0x00000004
Use setCategoryBitmask
to set object’s own mask, like below
playerBody->setCategoryBitmask(COL_MASK_PLAYER);
weaponBody->setCategoryBitmask(COL_MASK_WEAPON);
enemyBody->setCategoryBitmask(COL_MASK_ENEMY);
Use setCollisionBitmask
for physics response, with which objects you need physics response?
Do you want velocity should change when 2 objects collide? then mention this.
I think in your case, all blank is enough
playerBody->setCollisionBitmask(COL_MASK_BLANK);
weaponBody->setCollisionBitmask(COL_MASK_BLANK);
enemyBody->setCollisionBitmask(COL_MASK_BLANK);
To understand, i will give you another example, suppose there is ball & player which should jump on platform then initialize like below
platformBody->setCollisionBitmask(COL_MASK_BALL + COL_MASK_PLAYER);
playerBody->setCollisionBitmask(COL_MASK_PLATFORM);
ballBody->setCollisionBitmask(COL_MASK_PLATFORM);
Use setContactTestBitmask
for listener response, with which objects you need contact listener should be called? onContactBegin
etc
playerBody->setCollisionBitmask(COL_MASK_ENEMY);
weaponBody->setCollisionBitmask(COL_MASK_ENEMY);
enemyBody->setCollisionBitmask(COL_MASK_PLAYER + COL_MASK_WEAPON);
So in future if you add new objects then just ‘+’ with old mask values.
I hope this will help you and others as well.
Let me know if you have any doubts.