I once wrote a function in which I added geometrical cones to the scene. It looked like this:
func addZombies(i:Int, x: Float, y: Float, z: Float)
{
let node = SCNNode()
node.geometry = SCNCone(topRadius: 0.0, bottomRadius: 1, height: 2)
node.position = SCNVector3(x, y, z)
sceneView.scene.rootNode.addChildNode(node)
nodes.append(node)
}
where nodes was an array storing SCNNodes. Everything worked fine. If I had moved, the cones would have the exact positions as they had, a true "reality".
However, I purchased a nice 3D model of a zombie and I tried to change cones to the models. I found a solution of some sort and tried to implement it myself. This is what I came up with:
func addZombies(i:Int, x: Float, y: Float, z: Float)
{
guard let zombieScene = SCNScene(named: "art.scnassets/StrongZombie.DAE") else { return }
let zombieNode = SCNNode()
let zombieSceneChildNodes = zombieScene.rootNode.childNodes
for childNode in zombieSceneChildNodes
{
zombieNode.addChildNode(childNode)
}
zombieNode.position = SCNVector3(x, y, z)
zombieNode.scale = SCNVector3(0.5, 0.5, 0.5)
//zombieNode.look(at: (sceneView.pointOfView?.position)!)
sceneView.scene.rootNode.addChildNode(zombieNode)
nodes.append(zombieNode)
}
Unfortunately, even though it creates the zombies at the specific positions, if I move, the zombies "move" with me. They are displayed in relation to the moving camera which is undesirable for me. Can anyone help me out? I want them like the cones. Thx in advance