【问题标题】:How to get the current location of all nodes in a SceneKit scene如何获取 SceneKit 场景中所有节点的当前位置
【发布时间】:2021-05-16 05:39:01
【问题描述】:

我正在尝试在我的 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 文档中找不到任何关于如何在游戏节点中循环当前的文档。

【问题讨论】:

  • 你在哪里调用 mapLocationSave() ?
  • 在 viewDidLoad() 中,然后在玩家的每一个动作之后
  • self.gameScene 是如何定义的?
  • self.view.addSubview(scnView) scnView.scene = gameScene
  • 代替self.gameScene.rootNode....试试scnView.scene.rootNode....

标签: ios swift scenekit


【解决方案1】:

我想我已经修复了它购买通过相机节点可见的节点。

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

然后我每次都保存位置。

有没有更好的方法?

【讨论】:

    猜你喜欢
    • 2017-12-03
    • 1970-01-01
    • 2017-12-18
    • 1970-01-01
    • 2018-03-12
    • 2017-04-09
    • 1970-01-01
    • 2015-04-28
    • 1970-01-01
    相关资源
    最近更新 更多