如何找到添加force/Impulse后SCNNode落到的位置?
How to find the position a SCNNode will fall to after a force/Impulse was added?
我正在研究如何计算球的落点。基本上 "Ball" 被设置在那个人的手所在位置大约 2 英尺高的位置。
然后我想获取球的当前位置并对其应用 force/impulse 以使其向前发射。在它落地之前,我想尝试预测球将在何处落地。还有场景中地面的高度,矢量在所有位置上都是 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
我正在研究如何计算球的落点。基本上 "Ball" 被设置在那个人的手所在位置大约 2 英尺高的位置。
然后我想获取球的当前位置并对其应用 force/impulse 以使其向前发射。在它落地之前,我想尝试预测球将在何处落地。还有场景中地面的高度,矢量在所有位置上都是 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