SceneKit 相机仅在 x 轴上跟随对象? - Swift
SceneKit camera follow object only on x-axis? - Swift
如何根据移动球体的 x 位置移动相机,但同时忽略该球体的 y 和 z 坐标?这是我在 3 个维度上跟踪球体的代码:
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.camera?.usesOrthographicProjection = true
cameraNode.camera?.orthographicScale = 2
let constraint = SCNLookAtConstraint(target: sphere)
constraint.gimbalLockEnabled = true
self.cameraNode.constraints = [constraint]
cameraNode.position = SCNVector3Make(20, 20, 20)
cameraNode.eulerAngles = SCNVector3Make(0, 45, 0)
sphere.addChildNode(cameraNode)
我怎样才能只跟随球体的 x 位置,而不是同时跟随 y 和 z 位置?
从 sphere
中取消子相机,改为将其设为 root
的子相机。在移动球体的任何代码中,将相机的 x 位置设置为球体的位置。
// code moving sphere
cameraNode.position.x = sphere.position.x
如何根据移动球体的 x 位置移动相机,但同时忽略该球体的 y 和 z 坐标?这是我在 3 个维度上跟踪球体的代码:
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.camera?.usesOrthographicProjection = true
cameraNode.camera?.orthographicScale = 2
let constraint = SCNLookAtConstraint(target: sphere)
constraint.gimbalLockEnabled = true
self.cameraNode.constraints = [constraint]
cameraNode.position = SCNVector3Make(20, 20, 20)
cameraNode.eulerAngles = SCNVector3Make(0, 45, 0)
sphere.addChildNode(cameraNode)
我怎样才能只跟随球体的 x 位置,而不是同时跟随 y 和 z 位置?
从 sphere
中取消子相机,改为将其设为 root
的子相机。在移动球体的任何代码中,将相机的 x 位置设置为球体的位置。
// code moving sphere
cameraNode.position.x = sphere.position.x