I am trying to get the SCNVector3 of specific nodes in my SceneKit game so that I can determine how my player interacts with them in each turn. I have this running after the player performs a move action but the location in the mapList of my "pushable blocks" stays the same even though they are in a different location in the game.
var mapList: [SCNNode] = []
func mapLocationSave() {
let pushableNode = self.gameScene.rootNode.childNode(withName: "Pushables", recursively: true)
let wallNodes = gameScene.rootNode.childNode(withName: "Boxes", recursively: true)
let coinNodes = gameScene.rootNode.childNode(withName: "Coins", recursively: true)
for pushNode in pushableNode!.childNodes {
mapList.append(pushNode)
}
for wallNode in wallNodes!.childNodes {
mapList.append(wallNode)
}
for coinNode in coinNodes!.childNodes {
mapList.append(coinNode)
}
for node in mapList {
print(node.name!, node.worldPosition)
}
}
I suspect this is because I am not updating the mapList with the current in game locations and just looping through the gameScene.scn file?
I can't find any documentation about how to loop through current in game nodes in Apple docs.
self.view.addSubview(scnView)
scnView.scene = gameScene
– ViktorEvilself.gameScene.rootNode....
tryscnView.scene.rootNode....
– ryancrunchi