Game Development Reference
In-Depth Information
boxNode.physicsBody?.categoryBitMask
= CollisionCategoryObstacles
boxNode.physicsBody?.collisionBitMask
= CollisionCategorySpaceMan
//Add the following line to the Obstacle TubeNode() after
the physicsBody initialization:
tubeNode.physicsBody?.categoryBitMask
= CollisionCategoryObstacles
tubeNode.physicsBody?.collisionBitMask
= CollisionCategorySpaceMan
//Add the following line to the Obstacle CylinderNode()
after the physicsBody initialization:
cylinderNode.physicsBody?.categoryBitMask
= CollisionCategoryObstacles
cylinderNode.physicsBody?.collisionBitMask
= CollisionCategorySpaceMan
//Add the following line to the Obstacle torusNode() after
the physicsBody initialization:
torusNode.physicsBody?.categoryBitMask
= CollisionCategoryObstacles
torusNode.physicsBody?.collisionBitMask
= CollisionCategorySpaceMan
Now it's time to check your work. Build and run the game and you should be able to
move the spaceman around; only this time you should notice that he can go through the
nodes in the scene, he can go over some objects and he is stopped by the walls.
While this is great, you need a way for him to react to these collisions. Since you are mak-
ing a hide-and-seek game, you will want to know when you have found the enemy. In
finding the enemy, you will have to catch or collide with him. This is accomplished by us-
ing SCNPhysicsContactDelegate .
The first thing you will need to do is tell your class that you want to receive the
SCNPhysicsContactDelegate .
class GameViewController: UIViewController,
SCNSceneRendererDelegate, SCNPhysicsContactDelegate {
Search WWH ::




Custom Search