0

In my current app, I need to have multiple collisions with different nodes. I am pretty unfamiliar with the physics-world pertaining to Xcode. Within my ColliderType struct, contact with all nodes seem to work, except anything past the value type of 3. I am pretty confused with this stuff already, any help? Let me know if I should provide more code.

struct ColliderType {

static let player: UInt32 = 1
static let enemy: UInt32 = 2
static let coin: UInt32 = 3
static let arrow: UInt32 = 4

}
dr. mango
  • 43
  • 5
  • You need to show how you've set up the physics bodies of the objects, and in particular the `categoryBitMask`, `collisionBitMask`, and `contactTestBitMask` properties. You also need to say what's not working, like you're getting unexpected contact notifications, or expecting collisions but none are occurring, etc. – bg2b Jun 05 '22 at 21:43
  • Your 'coin' category is wrong because with a value of 3, its binary value ends in 0011 so any test for a contact with player (0001) or enemy (0010) will also match coin. When starting with SK, all category bit masks should be a power of 2. This might help - https://stackoverflow.com/a/40596890/1430420 – Steve Ives Jun 06 '22 at 08:02
  • @SteveIves Thanks for the insight, will change it over in my coding going forward! – dr. mango Jun 06 '22 at 11:21

1 Answers1

1

The problem was solved. I was missing some of the required contactTestBitMasks, and collisionBitMasks. To recap, the problem was that contact between the arrow and the enemy were not working. I thought this was something to do with my ColliderType Struct, however it was a simple error of not including the following when making my arrow:

arrow.physicsBody?.contactTestBitMask = ColliderType.enemy arrow.physicsBody?.collisionBitMask = ColliderType.enemy

dr. mango
  • 43
  • 5