Adding an enemy and collision detection

Create a new file called Enemy and, similar to how we created the Hero class, we will pass the GameSCNScene in it:

import SceneKit class Enemy: SCNNode{ var _currentScene: GameSCNScene! init(currentScene: GameSCNScene) { super.init() self.create(currentScene: currentScene) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } func create(currentScene: GameSCNScene){ print("spawn enemy") self._currentScene = currentScene let geo = SCNBox(width: 4.0, height: 4.0, length: 4.0, chamferRadius: 0.0) geo.firstMaterial?.diffuse.contents = UIColor.yellow self.geometry = geo self.position = SCNVector3Make(0, 20.0 , 60.0) self.physicsBody = SCNPhysicsBody.kinematic() self.name ...

Get Swift Game Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.