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

Apart from using b2Body::setTransform(), are there other ways to move a body around while keeping its dynamics ?

I want to move several bodies at the same time into one direction, pretty much like the movement of a crowd like the units in starcraft 2.

Does box2d already provide such features, if yes what is this called ? If not what precautions should I take while using setTransform ?

share|improve this question
Have you looked at the concept of flocking/boids? – Sidar Mar 20 '13 at 18:04
do they collide with each other ? – jokoon Mar 21 '13 at 18:24
Look at Bytes answer. One of the rules keeps them seperated. – Sidar Mar 21 '13 at 18:25

This would be the same as implementing a boids algorithm, and using Box2D to apply the forces required:

  • Separation: Steer to avoid crowding local flockmates

  • Alignment: Steer towards the average heading of local flockmates

  • Cohesion: Steer to move toward the average position of local flockmates

You can see an example in action here and get some details on its implementation here.

Applying the forces would be with Box2D functions to apply forces or impulses. You can read up of those here.

share|improve this answer
Can I still set an arriving behaviour with boids ? – jokoon Mar 24 '13 at 16:04
Absolutely. It actually allows you to ensure your entities aren't all crowding the arrival point. You can either use a follow the leader method and just have one entity arrive as normal, or use the above forces in addition to an arrival algorithm to make the entire flock exhibit the arrival behavior. As long as you maintain the 3 forces mentioned above, along with the steering force, you'll be set. – Byte56 Mar 24 '13 at 16:07
steering involves orientation, I want to do this without orientation. – jokoon Mar 27 '13 at 12:47
@jokoon It doesn't have to. Essentially you'll just have instantaneous rotation. This is easier to implement than steering with orientation. – Byte56 Mar 27 '13 at 14:01
How do I steer with box2d ? – jokoon Mar 27 '13 at 18:15

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.