0

I want to make a SKPhysicsBody in swift which allows another physics body to go through it without being affected. I cannot remove the physics body because I need the gravity. Any help is appreciated.

Rishi
  • 399
  • 6
  • 23

1 Answers1

1

"Physics bodies with the same collisionBitMask value will "pass-through" each other.".

This should answer your question.

George Hanna
  • 382
  • 2
  • 15
  • Thanks for the reply, I have set both of my `SKSpriteNodes` collition bit mask to 1, but they are unable to pass eachother – Rishi May 26 '17 at 11:09
  • Hi, did you also set the category and contact bit masks? – George Hanna May 26 '17 at 11:20
  • No, I did it now. and it is working. Thanks for your help. Also, How can I make a SKPhysicsBody only pass through the bottom to up of the node? – Rishi May 26 '17 at 12:02
  • *"Physics bodies with the same collisionBitMask value will "pass-through" each other."* Not sure I agree with this. If you want `bodyA` to allow `bodyB` to pass through it, then `bodyA`'s `collisionBitMask` must *not* include `bodyB`'s `categorybitMask`. https://stackoverflow.com/documentation/sprite-kit/6261/sknode-collision/29418/manipulating-contacttest-and-collison-bitmasks-to-enable-disable-specific-contac#t=201705261244093143533. – Steve Ives May 26 '17 at 12:44
  • @Rishi Setting both collision bit masks to 1 simply means that they will only collide with a body whose categoryBitMask is 1 (or, more correctly, has the 1 bit set on). The `contactTestBitMask` plays no part in collisions and is irrelevant in this discussion. – Steve Ives May 26 '17 at 12:48
  • 1
    @GeorgeHanna *"Physics bodies with the same collisionBitMask value will "pass-through" each other."* This is wrong - bodies with the same collision bit mask simply collide with the same things. This may or may not include each other. – Steve Ives May 26 '17 at 13:00
  • Yes, please redo this answer, if the `(p1.collisionBitMask && p2.categoryBitMask) == 0`, then the two objects will not collide. – Knight0fDragon May 26 '17 at 13:11
  • @Rishi, you have 2 options, you can add 2 child SKNodes with lines for physics bodies, or you can check the direction your sprite is contacting your body, and make that determination to activate collision. If you are doing a breakout style game, I would opt in the first one – Knight0fDragon May 26 '17 at 13:29
  • @Knight0fDragon Thank you for your help! I think I can check the direction that my player is coming from. – Rishi May 26 '17 at 15:23