Collision detection is not calling the NSLog in the didBeginContact function. The physics are working fine... Can someone show me what I've done wrong? Everything I've tried is giving me the same result.
import SpriteKit
class GameScene: SKScene, SKPhysicsContactDelegate {
let category0: UInt32 = 0x1 << 0
let category1: UInt32 = 0x1 << 1
let category2: UInt32 = 0x1 << 2
let category3: UInt32 = 0x1 << 4
let position1:CGFloat = 100
override func didMoveToView(view: SKView) {
self.physicsBody = SKPhysicsBody (edgeLoopFromRect:self.frame)
self.physicsWorld.gravity = CGVectorMake(0, -9)
physicsWorld.contactDelegate = self
let ground = SKSpriteNode(color: UIColor .redColor(), size: CGSizeMake(self.size.width, self.size.height/16))
ground.position = CGPointMake(self.size.width/2, self.size.height - self.size.height + ground.size.height)
ground.zPosition = position1
self.addChild(ground)
ground.physicsBody = SKPhysicsBody(rectangleOfSize: ground.size)
ground.physicsBody?.categoryBitMask = category2
ground.physicsBody?.contactTestBitMask = category1
ground.physicsBody?.collisionBitMask = category1
ground.physicsBody?.dynamic = false
ground.physicsBody?.affectedByGravity = false
ground.name = "Ground"
let launchingPad = SKSpriteNode(color: UIColor .redColor(), size: CGSizeMake(self.size.width/6, self.size.height/16))
launchingPad.position = CGPointMake(self.size.width - launchingPad.size.width/2 - 5, self.size.height - self.size.height + launchingPad.size.height * 4)
launchingPad.zPosition = position1
self.addChild(launchingPad)
launchingPad.physicsBody = SKPhysicsBody(rectangleOfSize: launchingPad.size)
launchingPad.physicsBody?.categoryBitMask = category1
launchingPad.physicsBody?.contactTestBitMask = category2
launchingPad.physicsBody?.collisionBitMask = category2
launchingPad.physicsBody?.dynamic = true
launchingPad.physicsBody?.affectedByGravity = true
launchingPad.name = "LaunchingPad"
func didBeginContact(contact: SKPhysicsContact) {
let firstBody = contact.bodyA.node as! SKSpriteNode
let secondBody = contact.bodyB.node as! SKSpriteNode
if ((firstBody.name == "LaunchingPad") && (secondBody.name == "Ground")){
NSLog("Contact")
}}}}