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.
We create a custom init
function, which takes in GameSCNScene
, so that we can add the current scene to the parent scene. We call the super.init
function...