Hunter Allen Hunter Allen - 7 months ago 240
iOS Question

How to animate character on Demand SceneKit Xcode Swift

hey I'm trying to figure out how to animate a .scn character i can get him in the scene but i can't lets say get him to play his animation when i press a button. Really i just need him to play his animation. back about a month ago i used to import the .scn file then the animation would play automatically as soon as he hit the screen but thats not what i need. I need it to play on demand and not just only when the app launches.


let GuyScene = SCNScene(named: "art.scnassets/Guy.scn")
let characterTopLevelNode: SCNNode = GuyScene!.rootNode.childNodeWithName("Guy", recursively: true)!


Check these two Apple sample projects. They both have characters animated on demand:

The steps are:

  1. Load a scn (or dae) file that contain the character and an animation (or just an animation and the skeleton of the character).
  2. Trigger the animation with addAnimation:forKey: on the character's root node.