Stop objects from colliding using SpriteKit : <p>I am testing out the features of SpriteKit and I ran into a problem. I was reading into bit masks, colliding, category, and contact. I get what they are, mostly at least, I don't get the point of category bitmasks, but I get colliding bitmasks which are the ones I need to solve my problem.</p>

<p>Ok so my problem is I have two different types of sprites: <em>object</em> and <em>second.</em> The names don't really make much sense but it is just for the sake of testing. I want second to have an impulse, and I want object to have a force. I was able to apply the respective vectors on the sprites, but I do not want them to collide with each other. I want them to pass right through and ignore the existence of each other.</p>

<p>I tried to solve that issue by assigning different collision bitmasks to each other:</p>

<pre><code>override func touchesBegan(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
    let texture = SKTexture(imageNamed: "pokeball")
    let object = SKSpriteNode(texture: texture)

    object.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: object.size.width,height: object.size.height))
    object.physicsBody?.affectedByGravity = false
    object.yScale = 0.5
    object.xScale = 0.5

    for t in touches {
        object.position = t.location(in: self)
    }
    self.addChild(object)
    object.physicsBody?.collisionBitMask = UInt32(4)
    object.physicsBody?.applyForce(CGVector(dx: 0, dy: 10))

}

override func touchesMoved(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
    let texture = SKTexture(imageNamed: "purple")
    let second = SKSpriteNode(texture: texture)
    let impulse : Double = 20
    let x = (impulse * Double(cosf(45)))
    let y = Double(impulse * Double(sinf(45)))
    let vector = CGVector(dx: x, dy: y)
    second.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: second.size.width,height: second.size.height))

    second.yScale = 1.5
    second.xScale = 1.5
    second.physicsBody?.isDynamic = true

    for t in touches {
        second.position = t.location(in: self)
    }
    self.addChild(second)
    second.physicsBody?.collisionBitMask = UInt32(1)
    second.physicsBody?.applyImpulse(vector)
}
</code></pre>

<p>So object has a bitmask of 4:</p>

<pre><code>object.physicsBody?.collisionBitMask = UInt32(4)
</code></pre>

<p>And second has a bitmask of 1:</p>

<pre><code>second.physicsBody?.collisionBitMask = UInt32(1)
</code></pre>

<p>I ran the simulator and they are still colliding with each other, so I went online and tried to look for some answers: I found one that says I must use numbers like:</p>

<blockquote>
  <p>these are bitmasks, you can't use arbitrary numbers 1,2,3,4,5 - you must use 1,2,4,8,16 and so on –</p>
</blockquote>

<p>Can someone explain why? However, that wasn't the issue because I was using 1 and 4</p>

<p>Next question I ran into said that I had to use binary numbers (0100) and (0010), I tried them, same issue: still colliding.</p>

<p>I will leave a picture of the collisions:
<a href="https://i.stack.imgur.com/reKz7.png">Collisions</a></p>

<p>Does anyone know why this is happening? My apologies in advance if this is a really dumb mistake or something that has already been asked, I just couldn't find it.</p>
