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 = "enemy" ...