I'm developing game with box2d for mobile.I created a world by these codes:
b2Vec2 gravity(0.0f, 9.8f);
bool doSleep = false;
b2World* g_World = new b2World(gravity, doSleep);
it's working so good.I have player object.The player fall down like:
y-axis: 0, 10, 30, 70..etc. I mean it's falling faster on each seconds.But i want it falls the same speed. like: y-axis: 0, 10, 20, 30..etc
Body fall under impact of gravity force, so it is logical, that it falling with acceleration.
If in your world should not to be gravity, then set zero gravity vector and set linear velocity for the body:
b2Vec2 gravity(0.0f, 0f);
bool doSleep = false;
b2World* g_World = new b2World(gravity, doSleep);
b2Body* body;
<.. creating body ..>
body->setLinearVelocity(0, 10);
If in your world gravity should be, then set gravity scale to zero in b2BodyDef:
b2Vec2 gravity(0.0f, 9.8f);
bool doSleep = false;
b2World* g_World = new b2World(gravity, doSleep);
b2BodyDef bodyDef;
bodyDef.gravityScale = 0;
< .. set other body parameters ..>
b2Body* body;
<.. creating body ..>
body->setLinearVelocity(0, 10);
If you use old version of Box2D, and there is no such field in b2BodyDef, then you have two solutions:
Set once linear velocity as in code above, and at each update step apply force opposite to gravity:
// Update cycle
g_World->Step(elapsed, 7, 4);
body->ApplyForceToCenter(-gravity);
Apply linear velocity at each update step, as said philipp:
// Update cycle
g_World->Step(elapsed, 7, 4);
body->ApplyLinearVelocity(0, 10);