1

I have tree that is built out of a series of joints. The anchor is the base/stump of the tree. My hero is currently not able to walk through the anchor. Setting collisionBitMask = 0 isn't working for the anchor but that approach does work for the individual joint segments.

So, essentially I just want to avoid this collision. Here is the code:

//code for anchor

let chunkHolder = SKSpriteNode(imageNamed: ImageName.ChunkHolder)
chunkHolder.position = anchorPoint

chunkHolder.physicsBody = SKPhysicsBody(circleOfRadius: chunkHolder.size.width / 2)
chunkHolder.physicsBody?.isDynamic = false
chunkHolder.physicsBody?.categoryBitMask = PhysicsCategory.chunkAnchor.rawValue
chunkHolder.physicsBody?.collisionBitMask = 0

addChild(chunkHolder)

//individual tree segements where hero correctly passes through:

for i in 0..<length {
    let treeSegment = SKSpriteNode(imageNamed: ImageName.ChunkTexture)
    let offset = treeSegment.size.height * CGFloat(i + 1)
    treeSegment.position = CGPoint(x: anchorPoint.x, y: anchorPoint.y - offset)
    treeSegment.name = "tree" + String(i)

    treeSegments.append(treeSegment)
    addChild(treeSegment)

    treeSegment.physicsBody = SKPhysicsBody(rectangleOf: treeSegment.size)
    treeSegment.physicsBody?.collisionBitMask = 0  
}

//joints

for i in 1..<length {
        let nodeA = treeSegments[i - 1]
    let nodeB = treeSegments[i]
    let joint = SKPhysicsJointPin.joint(withBodyA: nodeA.physicsBody!, bodyB: nodeB.physicsBody!, anchor: CGPoint(x: nodeA.frame.midX, y: nodeA.frame.minY))

    scene.physicsWorld.add(joint)
}

//for reference here is Hero's physics body:

self.physicsBody?.categoryBitMask = PhysicsCategory.hero.rawValue
self.physicsBody?.contactTestBitMask = PhysicsCategory.ground.rawValue

Also setting hero's collisionBitMask to 0 will not currently help because then hero will also fall through the ground / floor.

josh k
  • 268
  • 1
  • 11
  • I'd still like to disable the collision, but one handy trick is to set the physics body size to 1. The hero just walks over it fine. – josh k Apr 13 '17 at 20:09

1 Answers1

0

This was resolved by also setting the categoryBitMask to 0.

chunkHolder.physicsBody?.categoryBitMask = 0
chunkHolder.physicsBody?.collisionBitMask = 0
josh k
  • 268
  • 1
  • 11