简体   繁体   English

box2d部队(applyimpulse和applyforce)

[英]box2d forces (applyimpulse and applyforce)

Despite hours spent in front of box2d I still don't understand how does applyforce and applyimpulse works. 尽管在box2d前花了好几个小时,我仍然不明白applyforce和applyimpulse是如何工作的。 I've tried to use some visual to better understand what is going on (by making lines between the body position and the point of application) but the more I try the less it makes sense. 我试图用一些视觉来更好地理解正在发生的事情(通过在身体位置和应用点之间划线),但我尝试的越少,它就越有意义。

I would like to use applyimpulse to let my box2d body jump in the direction of the point of application (the mouse coordinates, in this attempt). 我想使用applyimpulse让我的box2d身体朝着应用点的方向跳跃(鼠标坐标,在此尝试中)。 It goes anywhere other than the desired point... 除了理想的点之外,它还有其他地方......

Here are some of my attempts so far: 以下是我目前的一些尝试:

b.ApplyImpulse(
new b2Vec2(g.mouseX/SCALE,g.mouseY/SCALE),
new b2Vec2(b.GetPosition().x,b.GetPosition().y));

and the opposite 与此相反

b.ApplyImpulse(
new b2Vec2(b.GetPosition().x,b.GetPosition().y),
new b2Vec2(g.mouseX/SCALE,g.mouseY/SCALE));

both producing unpredictable results which I don't understand at all. 两者都产生了不可预测的结果,我根本不理解。

Could please someone explain ApplyImpulse to me as if I were 5 years? 可以请某人向我解释ApplyImpulse,就像我5年一样吗? How can I decide the intensity of the impulse? 我怎样才能决定冲动的强度? And the direction? 和方向? No one seems to be explaining this on the internet. 似乎没有人在互联网上解释这一点。

Please forgive my poor physics background, I've tried in many different ways and this problem almost getting me stuck anytime I work with Box2d. 请原谅我糟糕的物理背景,我尝试过很多不同的方式,这个问题几乎让我在Box2d工作时遇到困难。

Many thanks in advance! 提前谢谢了!

我认为问题可能是画布的位置,用删除canvas.left替换你的鼠标坐标,它可以工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM