title: Calculate correct impluse or force to move a Box2D body to a specific position - Box2D
body: <p>i have a question about moving a Box2D body to a specific position without using this for example. </p>
  
  <pre><code>body-&gt;SetTransform(targetVector,body-&gt;GetAngle())
  </code></pre>
  
  <p>I have some code which works for applyForce (<a href="https://stackoverflow.com/questions/23157562/ios-box2d-body-follows-a-specific-path-based-on-an-array-of-points-with-fluctu">here</a>):</p>
  
  <pre><code>const float destinationControl = 0.3f;
  b2Vec2 missilePosition = _physicalBody-&gt;GetPosition();
  b2Vec2 diff = targetPosition - missilePosition;
  float dist = diff.Length();
  
  if (dist &gt; 0)
  {
  
  // compute the aiming direction
  b2Vec2 direction = b2Vec2(diff.x / dist, diff.y / dist);
  
  // get the current missile velocity because we will apply a force to compensate this.
  b2Vec2 currentVelocity = _physicalBody-&gt;GetLinearVelocity();
  
  // the missile ideal velocity is the direction to the target multiplied by the max speed
  b2Vec2 desireVelocity = b2Vec2(direction.x * maxSpeed, direction.y * maxSpeed);
  
  // compensate the current missile velocity by the desired velocity, based on the control factor
  
  b2Vec2 finalVelocity = control * (desireVelocity - currentVelocity);
  
  // transform our velocity into an impulse (get rid of the time and mass factor)
  float temp = (_physicalBody-&gt;GetMass() / normalDelta);
  
  b2Vec2 finalForce = b2Vec2(finalVelocity.x * temp, finalVelocity.y * temp);
  
  _physicalBody-&gt;ApplyForce(finalForce, _physicalBody-&gt;GetWorldCenter());
  
  }
  </code></pre>
  
  <p>But the when the <code>maxSpeed</code> is to high the body move over the point to fast.</p>
  
  <p>So does anyone know how to calculate a force (<code>ApplyForce</code>) or an impluse (<code>ApplyLinearImpulse</code>) to move the body to a target position (very exactly) in a specific time. </p>
  
  <p>Or a solution with the code above. I mean calculate the <code>maxSpeed</code> to move the body in a specific time to the target position.</p>
  
  <p>In my google search i found the interesting article from iforce about projected trajectory
  (<a href="http://www.iforce2d.net/b2dtut/projected-trajectory" rel="nofollow noreferrer">here</a>). Maybe this could be help too?</p>
  
  <p>Thank you in advance</p>