Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Box2D body velocity cap?

Tags:

c#

box2d

I have a body that has a mass of 10, and each cycle of the program I apply a force of 100 to it using the simple approach;

Vector2 force = new Vector2(0, 1) * 100;
bod.ApplyForce(force, bod.GetWorldCenter());

It works great, accelerates and all of that, but once it gets to a velocity of 10 (100 / 10 I assume) it won't go any faster. I am not a physicist by any means, but I do recall that the body should continually accelerate, like it would under gravity. Is this speed limit a result of the way Box2D does things, or am I royally screwing something up ? Also, what do I do to fix it.

NOTE: I get the same limited velocity if I use ApplyLinearImpulse instead of ApplyForce

Update: I am well aware of the overall max speed limit imposed by Box2D (in b2Settings.h). In my example, the item in question is moving well below this limit as changing the appplied force, be it 1000 or 10000 will always come around to the max velocity of (force / mass).

like image 386
A.R. Avatar asked Mar 09 '13 03:03

A.R.


1 Answers

You're hitting the maximum allowable velocity of an object. There are two ways to fix this:

  1. Adjust the maximum allowable velocity in your Box2D settings; Open up Settings and change the MaxTranslation float/const to a higher value, I'm assuming it's at the default of 2.0.

  2. Scale down your object size, perform the calculations necessary, scale your objects back up. This is the technically correct way of doing it, as Box2D's comments for MaxTranslation note:

The maximum linear velocity of a body. This limit is very large and is used to prevent numerical problems. You shouldn't need to adjust this.

So try #1, and if that does work, then it means that you're likely in need of scaling. Hope that helps.

like image 157
Mike P. Avatar answered Oct 27 '22 07:10

Mike P.