[英]How to get the current location of all nodes in a SceneKit scene
我試圖在我的 SceneKit 游戲中獲取特定節點的 SCNVector3,以便我可以確定我的玩家在每一輪中如何與它們交互。 我在玩家執行移動操作后運行此程序,但我的“可推送塊”的 mapList 中的位置保持不變,即使它們位於游戲中的不同位置。
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)
}
}
我懷疑這是因為我沒有用當前的游戲位置更新 mapList 並且只是循環通過 gameScene.scn 文件?
我在 Apple 文檔中找不到任何關於如何在游戲節點中循環當前的文檔。
我想我已經修復了它購買通過相機節點可見的節點。
let nodes = scnView.nodesInsideFrustum(of: cameraNode)
for node in nodes {
mapList.append(node)
}
然后我每次都保存位置。
有沒有更好的辦法?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.