ios - 如何获取 SceneKit 场景中所有节点的当前位置
问题描述
我试图在我的 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)
}
然后我每次都保存位置。
有没有更好的办法?
推荐阅读
- css - 如何使 animate.css 在 Rails 中工作?由于 animate-rails 不适用于 heroku
- arrays - 哈希数组
- javascript - 如何将光标插入符号移到它的活动编辑元素之外?
- javascript - API 和 Fiddler 的问题:登录 API 仅在 Fiddler 运行时有效:Laravel/Vue
- iis - NuGet.Server 在启动时崩溃
- git - 如何将 —help 传递给扩展命令?
- c# - 为实现相同接口的类创建默认方法
- python - 我怎样才能使这个自定义范围函数与负步骤一起工作?
- spring - Spring-Boot,获取方法级bean项目使用的所有注解值
- python - 使用来自 Python 的请求动态命名下载的文件时出现错误 22