简体   繁体   中英

box2d forces (applyimpulse and applyforce)

Despite hours spent in front of box2d I still don't understand how does applyforce and applyimpulse works. 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). 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? 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.

Many thanks in advance!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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