0

I have an SKNode set up as the "world" node, inside of this node I have children like characters, environment etc..

I've set up the world node to have a physicsBody of edgeLoopFromPath (world.path), and a category bit mask of "world", however I'm not sure how collision detection works for edgeLoopFromPath, my collision function looks like this:

func didBeginContact(contact: SKPhysicsContact) {
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
            firstBody = contact.bodyA
            secondBody = contact.bodyB
        } else {
            firstBody = contact.bodyB
            secondBody = contact.bodyA
        }
if ((firstBody!.categoryBitMask == PhysicsCategory.Hero) &&
            (secondBody!.categoryBitMask == PhysicsCategory.World)) {
                heroDidCollideWithWorld(firstBody!.node!, world: secondBody!.node!);
        }
}

theres more to the function but I want to keep it to the relevant portion, and the corresponding heroDidCollide function :

func heroDidCollideWithWorld(hero:SKNode, world:SKNode) {
        (hero as Character).negativeEffect.runningSpeed = 0
    }

however this isn't being hit. I have collision working for two bodies that are inside of the world node, but I can't figure out how to make the bodies inside the world node collide with the world (when they reach the edge of the node)

Abdul Ahmad
  • 9,673
  • 16
  • 64
  • 127
  • 1
    You need to test if `firstBody` is the world and the `secondBody` is the hero as well (see answer [here](http://stackoverflow.com/questions/20572309/detecting-collisions-in-sprite-kit)). – 0x141E Jan 04 '15 at 23:58
  • Do you have `showPhysics` enabled so you can see the physics bodies? – 0x141E Jan 05 '15 at 09:02
  • no I don't, I didn't know I can do that. I fixed the issue though, seems like one of my bodies wasn't set for collisions – Abdul Ahmad Jan 05 '15 at 12:19
  • @AbdulAhmad if the issue has been resolved, please post an answer and mark it as accepted. – ZeMoon Jan 05 '15 at 13:56

0 Answers0