Scenekit PhysicEngine跟随滚球 [英] Scenekit PhysicEngine follow rolling ball

查看:103
本文介绍了Scenekit PhysicEngine跟随滚球的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Apple的SceneKit中跟随一个旋转的球体.我在相机上添加了LookAt约束,当球体掉落时,凸轮aleays指向它,但是如果球体滚开,相机将停留在当前位置. 我希望凸轮像在第三人称射击游戏中那样跟随该球体,并与它保持预定义的距离.如果将凸轮设为球体的childNode,则当球滚动时,凸轮围绕其绕轨道"运动. 有什么想法可以用凸轮跟随球吗?

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?

推荐答案

这很简单.您只需要将摄像机节点在每帧的位置更改为球的

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.

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

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       
}

这篇关于Scenekit PhysicEngine跟随滚球的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆