Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios SceneKit摄影机仅在x轴上跟随对象?-敏捷的_Ios_Swift_3d_Camera_Scenekit - Fatal编程技术网

Ios SceneKit摄影机仅在x轴上跟随对象?-敏捷的

Ios SceneKit摄影机仅在x轴上跟随对象?-敏捷的,ios,swift,3d,camera,scenekit,Ios,Swift,3d,Camera,Scenekit,如何根据移动球体的x位置移动摄影机,但同时忽略该球体的y和z坐标?以下是我的代码,用于跟踪球体的3维: let cameraNode = SCNNode() cameraNode.camera = SCNCamera() cameraNode.camera?.usesOrthographicProjection = true cameraNode.camera?.orthographicScale = 2 let constraint = SCNLookA

如何根据移动球体的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位置?

球体
中取消相机的子对象,使其成为
的子对象。在任何正在移动球体的代码中,将摄影机的x位置设置为球体的x位置

// code moving sphere
cameraNode.position.x = sphere.position.x

sphere
取消相机的子对象,改为
root
的子对象。在任何正在移动球体的代码中,将摄影机的x位置设置为球体的x位置

// code moving sphere
cameraNode.position.x = sphere.position.x

是否无法访问“cameraNode.position.x”并直接赋值?是否无法访问“cameraNode.position.x”并直接赋值?