我在想如何计算一个球会落在哪里。基本上,“球”被设置在大约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)发布于 2016-09-05 04:00:19
下面是如何使用匀速运动方程计算水平位移。在SceneKit中,g的值被设置为默认值9.8,这意味着您处于mks系统中(米、公斤、秒)。
下面假设向上是正y方向,向前是正x,球可怕地移动的方向是正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 equationshttps://stackoverflow.com/questions/39303982
复制相似问题