I want to limit the maximum speed at which the body can travel.
The problem is that even if I am something like this answer suggests:
b2Vec2 vel = body->GetLinearVelocity();
float speed = vel.Normalize();
if ( speed > maxSpeed )
body->SetLinearVelocity( maxSpeed * vel );
What if, for example, right before I pinch speed, I apply tremendous force to the body? Even if linear speed is limited by maxSpeed at the moment, in the next timestep Box2D takes into account the value of b2Body :: m_force and effectively moves my body faster than maxSpeed.
So, I came up with this (I had to move the b2Body :: m_force file):
if ( speed > maxSpeed ) {
body->SetLinearVelocity( maxSpeed * vel );
body->m_force = b2Vec2(0, 0)
}
However, this still does not cope with the problem.
, , maxSpeed, , m_force , ?
, , , , -, , .
, Box2D?