Search code examples
iosswiftsprite-kitskphysicsbodybit-masks

Multiple collision bitmasks on 1 physics object?


Can one physics body have 2 different collision bit masks?

I have this code:

         bo.physicsBody?.collisionBitMask = noneCategory

But I'd like "bo" to also collide with "bumperCategory". So, I imagine it could look something like this:

        bo.physicsBody?.collisionBitMask = noneCategory && bumperCategory

That doesn't work. Is there anyway to do something similar to this?


Solution

  • You were close, but you need to bitwise OR instead of logical AND the two categories:

    bo.physicsBody?.collisionBitMask = noneCategory | bumperCategory