O'Reilly logo

Learning iOS 8 Game Development Using Swift by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding an enemy node

To check collision in SceneKit, we can check for collision between the hero and the ground. But let us make it a little more interesting and also learn a new kind of body type: the kinematic body.

For this, we will create a new box called enemy and make it move and collide with the hero. Create a new global SCNNode called enemyNode as follows:

  let scnView: SCNView!
  let _size:CGSize!
  var scene: SCNScene!
  var heroNode:SCNNode!
  var enemyNode:SCNNode!

Also, create a new function called addEnemy to the class and add the following in it:

func addEnemy(){ let geo = SCNBox(width: 4.0, height: 4.0, length: 4.0, chamferRadius: 0.0) geo.firstMaterial?.diffuse.contents = UIColor.yellowColor() enemyNode = SCNNode(geometry: geo) enemyNode.position ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required