I keep getting "fatal error: unexpectedly found nil while unwrapping an Optional value" in the following code
let ballCategoryName = "ball"
class GameScene: SKScene, SKPhysicsContactDelegate {
override func didMoveToView(view: SKView) {
let borderBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
borderBody.friction = 0
self.physicsBody = borderBody
let ball = childNodeWithName(ballCategoryName) as! SKSpriteNode
ball.position = CGPointMake(self.size.width / 2, self.size.height / 2)
ball.physicsBody?.dynamic = true
ball.physicsBody = SKPhysicsBody(circleOfRadius: ball.size.height / 2)
ball.physicsBody!.applyImpulse(CGVector(dx: 2.0, dy: -2.0))
self.addChild(ball)
the Error Appears at "let ball = childNodeWithName(ballCategoryName) as! SKSpriteNode" Wondering if someone could help me out here on why this keeps appearing