0
votes

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.

1
Where do you call mapLocationSave() ?ryancrunchi
in viewDidLoad() and then after every move by the playerViktorEvil
how is self.gameScene defined ?ryancrunchi
self.view.addSubview(scnView) scnView.scene = gameSceneViktorEvil
instead of self.gameScene.rootNode.... try scnView.scene.rootNode....ryancrunchi

1 Answers

0
votes

I think I have fixed it buy getting the nodes that are visible through the camera node.

let nodes = scnView.nodesInsideFrustum(of: cameraNode)
        for node in nodes {
            mapList.append(node)
        }

I then save the locations at every turn.

is there a better way?