首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何找到在添加了力/脉冲后SCNNode将下降到的位置?

如何找到在添加了力/脉冲后SCNNode将下降到的位置?
EN

Stack Overflow用户
提问于 2016-09-03 14:35:27
回答 1查看 210关注 0票数 1

我在想如何计算一个球会落在哪里。基本上,“球”被设置在大约2英尺高的位置,在那里的家伙的手。

然后我想要获得球的当前位置,并对它施加一个力/脉冲,这将使它向前发射。在球落地之前,我想预测一下球的落地位置。此外,场景中地面的高度,向量在所有位置都是0。

那么基本上可以计算出你的球会落在哪里吗?

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-05 04:00:19

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

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

首先求出沿y方向的脉冲所产生的初始垂直速度(v0y):

代码语言:javascript
复制
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)。因为你要找平方根,所以你会得到+和-两个答案,使用负值。

代码语言:javascript
复制
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):

代码语言:javascript
复制
t = (vy – v0y) / g
    remember, vy and g are both negative

现在你需要沿x的速度:

代码语言:javascript
复制
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):

代码语言:javascript
复制
x = vx * t
    t is the value you got from the vertical motion equations
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39303982

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档