Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm making a 2d shooter ala Geometry Wars. I've got my own simple physics at work driving the background grid and all my entities. To move anything in the world I apply a Vector2d force to it. The 'engine' calculates the resulting acceleration and therefore the velocity.

I am trying to port some code I found which implements the classic 'Boids' flocking algorithm, but the code I have works by calculating the Boids' velocities directly, so If i use it as is, it bypasses my physics engine. How I can translate the velocity vectors into force vectors that I can apply to the Boids and which will result in the proper velocities via my physics engine.

share|improve this question
One question to your question: are your bodies capable of theoretically infinite accelerations? If yes, then if the algorithm tells an entity to change its velocity from v0 to v1, you can compute the acceleration as a = (v1 - v0 )/dTime .Then you can apply the F = m * a force to that entity and it will have this velocity at the next time step. But, there's another problem: what integration method do you really use? Depending on your update logic and integrator, this simple approach might not work. I assumed a simplistic explicit integrator logic (e.g. Euler). – teodron Dec 7 '12 at 16:49
If you have velocity, mass and time: Force = (mass * velocity) / time. – Asakeron Dec 7 '12 at 16:53

It depends how your physics engine works, but you can probably use Newton's second law:

F = m × a

Where m is the mass of the object and a is its acceleration (a vector). The acceleration is the dv/dt derivative, which can be approximated by dividing the change in velocity by the timestep:

F = m × (velocity - previous_velocity) / timestep

Of course this only works reliably if the force you're applying is the only one affecting the entity. Otherwise you may experience numerical inaccuracies.

share|improve this answer
Be careful about using × for 'times' - a lot of people will (understandably) interpret that as 'cross product'... – Steven Stadnicki Dec 7 '12 at 19:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.