Creating the hero class and physics

Create a new class, called Hero, and add the following code to it:

import SceneKit
class Hero: SCNNode {
    
    var isGrounded = false
    
    var monsterNode = SCNNode()
    var jumpPlayer = SCNAnimationPlayer()
    var runPlayer = SCNAnimationPlayer()
    
    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){
    
    }
} 

At the top of the create variables, which we will be needing later, we create a bool to check whether the character is grounded or not. Create a SCNNode to access the character node and create two SCNAnimationPlayer variables to access the player animations. ...

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.