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
}