A small example project I've live coded at the Google Developer Group conference DevFest 2017 in Karlsruhe Germany.
http://www.devfestka.de/programm
It is based on ARKit and demonstrates general 3D development basics, SceneKit, loading 3D Models, the PhysicsEngine and the AVAudioPlayer.
Checkout commit "Initial version"
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let node = SCNNode()
let box = SCNBox(width: 0.1, height: 0.1, length: 2, chamferRadius: 0)
box.firstMaterial?.diffuse.contents = UIColor.red
box.firstMaterial?.lightingModel = .constant
node.geometry = box
node.opacity = 0.5
if let pov = sceneView.pointOfView {
node.position = pov.position
node.position.y -= 0.3
node.eulerAngles = pov.eulerAngles
}
sceneView.scene.rootNode.addChildNode(node)
}
See:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
...
addPhysics(laser)
animateLaser(laser)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
...
assets.playSoundEffect(ofType: .laser)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
...
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
laser.removeFromParentNode()
}
}
override func viewDidLoad() {
...
addNewTieFighter()
}
private func addNewTieFighter() {
...
animateFighter(fighter)
}
func physicsWorld(_ world: SCNPhysicsWorld, didBegin contact: SCNPhysicsContact) {
...
contact.nodeA.removeFromParentNode()
contact.nodeB.removeFromParentNode()
}
func physicsWorld(_ world: SCNPhysicsWorld, didBegin contact: SCNPhysicsContact) {
...
assets.playSoundEffect(ofType: .explosion)
createExplosion(contact.nodeA.position)
}
func physicsWorld(_ world: SCNPhysicsWorld, didBegin contact: SCNPhysicsContact) {
...
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.addNewTieFigher()
}
}