Assume that there is a circle and it can be moved by using keyboard arrows.Is required that increasing speed over time like increasing car speed. For example; max speed is 25 and time to reach max speed shall be 5 sec. Over 5 sec the speed will reach to max speed. Does Box2d handle that situation?. I tried setting linear valocity but it seems to make the circle have constant speed instead of increased speed over time.

Thank You!

Note: I'm using Box2DWeb Javascript port of Box2D.

  • \$\begingroup\$ Increasing the speed over time is known as acceleration. Box2D can handle acceleration. \$\endgroup\$
    – House
    Jul 2, 2013 at 17:21
  • \$\begingroup\$ Box2d is best when want to run simulations. The more tightly you want to control things the worse it is. At your point I would just do the math yourself. Not to mention Box2D is kinda built around forces and there is nothing linear about how forces effect thigns. \$\endgroup\$ Jul 2, 2013 at 17:54

2 Answers 2


With Box2D you should just have to apply an Impulse to your object, instead of setting the velocity manually.

ApplyImpulse(direction,point)  //Direction = vector

For the point, you can always use the center of your Body object by using:


By applying small impulses, you will see your object accelerate. The speed of acceleration will depend on a bunch of variables, such as the force of your impulse, the weight of your object, friction, etc...


You'll have to time the amount of acceleration per frame yourself. There is no built-in function to increase velocity over time to a cap as you described. Extending Jon's answer, you probably end with up some code like this (adapted from http://www.iforce2d.net/b2dtut/constant-speed check it out the page, its very similar to what you want to to do):

timer = 5.0f; // 5 seconds    
   update(float delta){ 
        timer -= delta; //timer keeps track of time left
        b2Vec2 vel = body->GetLinearVelocity();
        float desiredVel;
        if(timer > 0)
            desiredVel = MIN_VEL + * acceleration * delta; //m/s
        float velChange = desiredVel - vel.x;
        float impulse = body->GetMass() * velChange; //disregard time factor
        body->ApplyLinearImpulse( b2Vec2(impulse,0), body->GetWorldCenter() );

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .