4

I have a player with:

categoryBitMask = playerCategory
contactTestBitMask = enemyBulletCatgory

This character shoots bullets with:

categoryBitMask = bulletCatgory
contactTestBitMask = enemyCategory

but when I shot the the bullet the bullet is a bit over my player and my player jumps a bit cause they interact, though they are not set up to do so.

How do I make SKPhysicsBodies ignoer eachother?

Thomasn
  • 101
  • 5
  • 1
    Set their collisionBitMask to zero. By default they're set to collide with everything. – 0x141E Aug 11 '14 at 16:37
  • 1
    I could do that, but then my player would fall through the floor. If I only set the bullets collisionBitMask to zero it still interacts even if the players collisionBitMask is not the bit mask of the bullet – Thomasn Aug 11 '14 at 17:08
  • You can set each node's collisionBitMask to collide or not collide with any other node. For example, you could set player.collisionBitMask = floorCategory | wallCategory | ballCategory. However, if the other node moves, you will need to set the collision bits for the other node accordingly to ensure that they collide correctly. For example, if the ball is a moving object, set ball.collisionBitMask = playerCategory. – 0x141E Aug 11 '14 at 17:22
  • for the player I got: physicsBody.collisionBitMask = floorCategory | blokkCategory, and for the bullet I got: p.physicsBody.contactTestBitMask = enemyCategory , so they should not interact. They are both moving by the way :) Could I listen for the event and just cancel any interaction if they collide? though that would create some overhead. – Thomasn Aug 11 '14 at 17:49
  • You can detect contacts by overriding didBeginContact. – 0x141E Aug 11 '14 at 20:11
  • The problem was that i did my bitMasks wrong... I did: 0b0001, 0b00010, 0b00011 I changed ut too: 0b1, 0b10, 0b100 and it all worked out.. Thanks a million anyway :) – Thomasn Aug 11 '14 at 20:42
  • 1
    Try let playerCategory:UInt32 = 0x1 << 0, let enemyCategory:UInt32 = 0x1<<1, etc. – 0x141E Aug 11 '14 at 20:50

0 Answers0