【问题标题】:Scenekit PhysicEngine follow rolling ballScenekit PhysicEngine 跟随滚动球
【发布时间】:2015-09-05 23:31:38
【问题描述】:

我想跟随 Apple 的 SceneKit 中的旋转球体。我已经为相机添加了一个 LookAt 约束,当球体下降时,cam aleays 指向它,但如果球体滚开,相机将保持在其当前位置。 我希望凸轮跟随这个球体,就像在第三人称射击游戏中一样,与它有预定义的距离。如果我将凸轮设为球体的 childNode,则当球滚动时,凸轮会围绕它“旋转”。 有什么想法可以用摄像头跟随球吗?

【问题讨论】:

  • 你可以运行节点上运行的所有动作来跟随相机,虽然这不是一个很方便的方式。

标签: ios swift physics scenekit


【解决方案1】:

这很简单。您只需将相机节点在每一帧的位置更改为球的presentationNode 加上一个偏移量,以避免在其中。

我对 Swift 不太熟悉,但代码看起来像这样:

func renderer(aRenderer: SCNSceneRenderer, didSimulatePhysicsAtTime time: NSTimeInterval){
    var ballP = ballNode.presentationNode.position
    // Offset the camera up and on X:
    var cameraP = SCNVector3(x: ballP.x+5, y: ballP.y+10, z: ballP.z)
    cameraNode.position = cameraP       
}

【讨论】:

    猜你喜欢
    • 2019-04-14
    • 2017-08-28
    • 2016-02-24
    • 1970-01-01
    • 2017-09-12
    • 2017-01-29
    • 1970-01-01
    • 2016-04-18
    • 1970-01-01
    相关资源
    最近更新 更多