拿到球的位置在SCN文件中创建

问题描述 投票:1回答:1

我创建使用Xcode的(你可以看到下图)SCN文件,其中有两个节点(一个球体和一个平台)。我设置了球的位置:

SCN editor window showing a sphere Readout of the sphere position 0.074 0.391 0.392

我用它创建了一个节点的平台,您可以调整大小和移动类:

Screenshot

按下一个按钮后它把我的SCN文件,而不是该平台(具有相同的规模,位置和方向)问题是我不知道如何从现场查看球的位置。

  let sphere = SCNNode()
  self.scene.parent!.enumerateChildNodes { (node, _) in
        if node.name == "sphere" {
            sphere = node
            sphere.position = node.position
            print(sphere.position)
        }
    }

使用代码总是打印,我设立在SCN文件(你可以在上面看到)的位置,但我想它在视图中的实际位置。

ScreenShot

swift scenekit arkit scnscene arscnview
1个回答
2
投票

随着sphere.position你会得到相对于其父节点sphere的位置。如果你想在场景中的位置,你必须使用sphere.worldPosition

© www.soinside.com 2019 - 2024. All rights reserved.