ios - 如何找到添加力/脉冲后 SCNNode 将落到的位置?

标签 ios swift scenekit

我正在尝试弄清楚如何计算球的落点。基本上,“球”被设置在那个人的手所在位置大约 2 英尺高的位置。

然后我想获取球的当前位置并对其施加力/冲量,使其向前发射。在它落地之前,我想尝试预测球将在何处落地。还有场景中地面的高度,矢量在所有位置上都是 0。

那么基本上可以计算出球的落点吗?

Ball.position = SCNVector3Make(Guy.presentationNode.position.x, Guy.presentationNode.position.y, Guy.presentationNode.position.z)          
var Currentposition = Ball.presentationNode.position
var forceApplyed = SCNVector3(x: 50.0, y: 20.0 , z: 0.0)
var LandingPiont = Currentposition + forceApplyed // Error on this line of code saying "+" cannot be applyed to CGVector
Ball.physicsBody?.applyForce(forceApplyed, atPosition: Ball.presentationNode.position, impulse: true)

最佳答案

下面介绍如何使用匀速运动方程计算水平位移。 g 的值在 SceneKit 中设置为默认值 9.8,这意味着您处于 mks 系统(米、千克、秒)中。

下面假设向上是正y方向,向前,球水平移动的方向,是正x。一定要注意沿 y 方向运动的标志。 (以下不是代码,尽管它看起来是这样格式化的。)

首先找到由于沿 y 方向的冲量产生的初始垂直速度 (v0y):

v0y = Jy / m
    m is ball’s mass (in kilograms)
    Jy is impulse along the y  (forceApplied.y)
    (v0y will be negative if Jy is negative)

接下来求球到达地面时的垂直速度分量 (vy)。因为您正在寻找平方根,所以您将同时获得 + 和 – 答案,请使用负值。

vy ^2 = v0y ^2  +  2 * g * y
    g is your gravitational constant
    y is ball’s initial height 
    both g and y are negative in your case
    use the negative root, i.e.  vy should be negative

求球在空中停留的时间 (t):

t = (vy – v0y) / g
    remember, vy and g are both negative

现在您需要沿 x 方向的速度:

vx = Jx / m
    Jx is impulse along x  (forceApplied.x)
    m is the ball’s mass
    (the velocity along the x remains constant)

最后,求解沿 x 的位移 (x):

x = vx * t
    t is the value you got from the vertical motion equations

关于ios - 如何找到添加力/脉冲后 SCNNode 将落到的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39303982/

相关文章:

xcode - 文档 “filename.dae”无法保存

IOS:多点连接框架

swift - 返回集合的切片类型

ios - Xcode 6.1 - 结构实例控制台错误

swift - 查找与 OptionSet 的值关联的名称

ios - UICollectionView 水平滚动

ios - 注意到场景包中节点位置进入某个边界框了吗?

swift - 在 SceneKit 中按所需方向旋转后如何平移相机节点位置?

ios - 环绕排除路径后 UITextView 的内容大小没有改变

ios - Swift:cellForRowAtIndexPath 中出现意外结果