swift - SceneKit 相机没有移动到正确的位置

标签 swift xcode scenekit swift-playground

我正在 Solar System swift playground 上工作。如果单击该行星,我希望相机放大该行星。我目前遇到的问题是相机无法放大到正确的位置。这是我正在使用的代码。

public let camera = SCNNode()
camera.camera = SCNCamera()
camera.position = SCNVector3(x: 0, y: -70, z: 50)
camera.eulerAngles = SCNVector3(x: 0.74533, y: 0, z: 0)

let location = planetNodes[i].convertPosition(planetNodes[i].position, to: camera)
let radius = planetNodes[i].position.y
let moveCameraAc = SCNAction.move(to: location, duration: 2)
moveCameraAc.timingMode = .easeInEaseOut
camera.runAction(moveCameraAc)

它总是会移动到场景中的不同位置。我无法弄清楚它是如何找到移动到哪里的。

提前致谢!

最佳答案

我想通了!代码需要看起来像

let location = holderNodes[i].convertPosition(planetNodes[i].position, to: scene.rootNode)

holderNodes[i]是planetNodes[i]的父节点,scene.rootNode是camera的父节点。

关于swift - SceneKit 相机没有移动到正确的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49548258/

相关文章:

swift - 可哈希协议(protocol)的自动原子唯一 ID

html - 如何在 TextView 中显示 HTML 文本

swift - 如何让我的文件出现在 Xcode 的项目导航器中?

ios - Xcode - 找不到测试主机

c++ - 为什么没有抓到返回值就没有错误呢?

swift - 如何更改 SCNParticleSystem 中粒子的亮度?

swift - 如何正确使用Scenekit的类别 mask 、碰撞 mask 和物理体、contactTestBitMask并做出适当的碰撞?

swift - "Cannot assign to the result of this expression"变量 (var) 引起的错误

swift - 无法将变量设置为文本字段的值

ios - 2个 View Controller ,每个都有自己的xib,其中一个是另一个的子类?