I've got a problem with swift and Sprite kit. My game is supposed to detect collision between enemies and the player(spaceship). `
func didBeginContact(contact: SKPhysicsContact){
let firstBody:SKPhysicsBody = contact.bodyA
let secondBody:SKPhysicsBody = contact.bodyB
if (firstBody.categoryBitMask == BodyType.bulletMask) && (secondBody.categoryBitMask == BodyType.enemyMask){
collisionWithBullet(firstBody.node as! SKSpriteNode,person: secondBody.node as! SKSpriteNode)
}
if (firstBody.categoryBitMask == BodyType.spaceShipMask) && (secondBody.categoryBitMask == BodyType.enemyMask){
collisionWithSpaceShip(firstBody.node as! SKSpriteNode,person: secondBody.node as! SKSpriteNode)
}
}
When my spaceship hit an enemy or if the bullet hit an enemy, i'll have this error :
"fatal error: unexpectedly found nil while unwrapping an Optional value"
How can I fix this ? Thanks.