如何根据移动球体的x位置移动摄影机,但同时忽略该球体的y和z坐标?以下是我的代码,用于跟踪三维球体:

    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位置设置为球体的x位置。

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

07-27 19:28