I have found nothing on the internet about how to do this. Im simply trying to run a line of code when to physics body touch. In this case I have an SKSpriteNode with a physics body and another for the ground. When they touch it should run the line of code this is all I have found so far.
let catGroup:UInt32 = 0x1 << 0
let groundGroup:UInt32 = 0x2 << 1
cat.physicsBody?.categoryBitMask = catGroup
cat.physicsBody?.contactTestBitMask = groundGroup
ground.physicsBody?.categoryBitMask = groundGroup
ground.physicsBody?.contactTestBitMask = catGroup
and here is where I'm confused
func didBeginContact(contact: SKPhysicsContact) {
var firstBody: SKPhysicsBody
var secondBody: SKPhysicsBody
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask
{
firstBody = contact.bodyA
secondBody = contact.bodyB
}
else {
firstBody = contact.bodyB
secondBody = contact.bodyA
}
if firstBody.categoryBitMask==0 && secondBody.categoryBitMask==1 {
print("contact")
}
}
so should i be replacing first body and second body with catGroup and groundGroup? Im not sure how to do this