I really enjoyed the book and I completed all the tutorials. However, there is one topic I didn’t see covered that I’m curious about. What if one wanted to have an “animated” 3D object in a scene. An example: I want to create a tank with a rotating turret. The tank should move around the scene as one object, but the turret is able to rotate in any direction and possibly even the gun could raise & lower. How would one approach such a task? Would you create multiple nodes and combine them with a joint? Or, I recall from SpriteKit (though it has been a long while) that there is a way to have an “animated” spritekit node. Is there an equivalent method in SceneKit?
Just hoping to hear any thoughts/idea on an approach… not detailed code examples (unless you’re feeling generous!) or a link to another tutorial/example.
Thanks,
Tom
I can point you in the direction to study the Apple™ “Fox” demo.
Go to the Apple Developer page, download the “FoxBuildingaSceneKitGamewiththeXcodeSceneEditor” Study the “Character.swift” file. it demonstrates how they animate a Fox character.
Here is the character animation implementation it uses a 3D model (fox) that was animated in an external application.
// MARK: Configure animations
// Some animations are already there and can be retrieved from the scene
// The "walk" animation is loaded from a file, it is configured to play foot steps at specific times during the animation
characterTopLevelNode.enumerateChildNodes { (child, _) in
for key in child.animationKeys { // for every animation key
let animation = child.animation(forKey: key)! // get the animation
animation.usesSceneTimeBase = false // make it system time based
animation.repeatCount = Float.infinity // make it repeat forever
child.addAnimation(animation, forKey: key) // animations are copied upon addition, so we have to replace the previous animation
}
}
walkAnimation = CAAnimation.animationWithSceneNamed("game.scnassets/walk.scn")
walkAnimation.usesSceneTimeBase = false
walkAnimation.fadeInDuration = 0.3
walkAnimation.fadeOutDuration = 0.3
walkAnimation.repeatCount = Float.infinity
walkAnimation.speed = Character.speedFactor
walkAnimation.animationEvents = [
SCNAnimationEvent(keyTime: 0.1) { (_, _, _) in self.playFootStep() },
SCNAnimationEvent(keyTime: 0.6) { (_, _, _) in self.playFootStep() }]
}
Thank you! I will check out that example.
Holy moly! This sample is amazing! I haven’t looked at the code yet, but I built it and installed on my iPhone. And I was blown away. Thank you for recommending it.
There are a few more project examples. This one is better…
BadgerAdvancedRenderinginSceneKit"
Run on a device or Mac (to slow on the simulator)
Also watch this video, skip to time code 29:40. Then after you watch it, go back and watch to entire vid (apologies for the strong french accent Lol!)
Oh very cool. I have put this one on my phone as well. You say there is a video as well?