Scenekit PhysicEngine follow rolling ball

空扰寡人 提交于 2019-12-10 10:25:48

问题


I want to follow a rotating sphere in Apple's SceneKit. I've added an LookAt Constraint to the camera and as the sphere falls down the cam aleays points to it but if the sphere rolls away the camera stays at its current position. I want the cam to follow this sphere like in a third persond shooter with a predefined distance to it. If I make the cam a childNode of the sphere the cam "orbits" around it as the ball is rolling. Any ideas how I can follow the ball with the cam?


回答1:


It's pretty simple. You just need to change the camera node's position at each frame to the ball's presentationNode plus an offset to avoid being inside of it.

I'm not too familiar with Swift but the code would look something like this:

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       
}


来源:https://stackoverflow.com/questions/30947351/scenekit-physicengine-follow-rolling-ball

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!