问题
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