Calculating distance travelled by a b2body before it stops in Box2D

自作多情 提交于 2019-12-11 20:47:22

问题


I have a zero gravity world. I have a catapult using which a box2d body is shot into space.

I calculate a certain force and apply it to the body along with a certain damping factor.

My code hence looks like this:

 _body->ApplyForce(force, b2Vec2(position.x / PTM_RATIO, position.y / PTM_RATIO));
float damping = 1.5f;
_body->SetLinearDamping(damping);

I want to calculate the distance it travels before it ultimately stops. What is the correct way to calculate it?

I am calculating it using -

distance = force.Length() * (force.Length() / damping)

Is that correct?


回答1:


It looks like its the trajectory you are after. In that case I would recommend having a read through that tutorial. I have implemented that in to a golf game and it work fine for what I needed. Let me know if that answers your question.

iForce2D Box2D Tutorials - Projected Trajectory



来源:https://stackoverflow.com/questions/18526062/calculating-distance-travelled-by-a-b2body-before-it-stops-in-box2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!