Search code examples
objective-ccollision-detectionphysicsskspritenode

How to exclude multiple physicsbody collisionBitMask


I found from other SO' answer that you can exclude collisions btw same type of spritenode's physicsbody, by using ~ in the bitmask like so:

    self.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:self.size.width/2.0];
    self.minionLife = 1.0;
    self.minionSpeed = 60.0;
    self.minionPath = 0;
    self.physicsBody.categoryBitMask = cat_enemy1;

    // does not collide with itself
    self.physicsBody.collisionBitMask = ~cat_enemy1; // here

Question is how to add more exclusions to this collisionBitMask?

I tried:

self.physicsBody.collisionBitMask = ~cat_enemy1 | ~cat_playerShip; // here

But not working.


Solution

  • You have to or it and then to negate it …:

    … = ~(cat_enemy1 | cat_playerShip);
    

    … or to and it:

    … = ~cat_enemy1 & ~cat_playerShip;