Adding character animation
To make sure that the correct animation gets played when the player runs and jumps, we have to extract the run and jump animations from the collada
file.
In the Hero class's create function, after updating the anchor point, add the following code to get the run and jump animations:
// get the animation keys and store it in the anims let animKeys = monsterNode.animationKeys.first let animPlayer = monsterNode.animationPlayer(forKey: animKeys!) let anims = CAAnimation(scnAnimation: (animPlayer?.animation)!) // get the run animation from the animations let runAnimation = Hero.animation(from: anims, startingAtFrame: 31, endingAtFrame: 50) runAnimation.repeatCount = .greatestFiniteMagnitude runAnimation.fadeInDuration = 0.3 runAnimation.fadeOutDuration = 0.3 //set the run animation to the player runPlayer = SCNAnimationPlayer(animation: SCNAnimation(caAnimation: runAnimation...