簡體   English   中英

SceneKit相機僅在x軸上跟隨對象? -迅捷

[英]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位置設置為球體的x位置。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM