title: Apply Force in Box2d correctly
body: <p>I have a body and I want to move it by applying a force on it. So In each frame update event I apply force like this:</p>
  
  <pre><code>body-&gt;ApplyForceToCenter(100 * body-&gt;GetMass() * b2Vec2(vel.x, vel.y), true);
  </code></pre>
  
  <p>But I have a serious problem here. As I have to update Box2d world with constant time step</p>
  
  <blockquote>
    <p>We also don't like the time step to change much. A variable time step
    produces variable results, which makes it difficult to debug. So don't
    tie the time step to your frame rate (unless you really, really have
    to). <a href="http://www.box2d.org/manual.html" rel="nofollow">[see here]</a></p>
  </blockquote>
  
  <p>I wrote this code to update physics world:</p>
  
  <pre><code>void Box2dManager::update(float dt)
  {
      static const double step = 1.0/60.0;
      static double accumulator = 0.0;
  
      // TODO check do we need this?
      // max frame time to avoid spiral of death
      if ( dt &gt; 0.25 )
          dt = 0.25;
  
      accumulator += dt;
  
      while (accumulator &gt;= step)
      {
          m_world.Step(step, VELOCITY_ITERATIONS, POSITION_ITERATIONS);
          accumulator -= step;
      }
  }
  </code></pre>
  
  <p>The result is that the movement of the body becomes choppy when I apply force in different directions using a sneaky joystick, no matter even if it moves slow or fast. And when I update world by time step of my frame rate (<code>dt</code> function argument), only then the movement becomes smooth. How can we explain this? And how can we fix this?</p>
  
  <p>Also here this is not only the problem of moving choppy, but there is another issues too, because actually I am not applying constant force as FPS is not constant and I apply force in each frame only once. So during different periods I apply the same force with the same time interval (world step).</p>