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 ?

  • \$\begingroup\$ Have you looked at the concept of flocking/boids? \$\endgroup\$ – Sidar Mar 20 '13 at 18:04
  • \$\begingroup\$ do they collide with each other ? \$\endgroup\$ – jokoon Mar 21 '13 at 18:24
  • \$\begingroup\$ Look at Bytes answer. One of the rules keeps them seperated. \$\endgroup\$ – 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.

  • \$\begingroup\$ Can I still set an arriving behaviour with boids ? \$\endgroup\$ – jokoon Mar 24 '13 at 16:04
  • \$\begingroup\$ 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. \$\endgroup\$ – MichaelHouse Mar 24 '13 at 16:07
  • \$\begingroup\$ steering involves orientation, I want to do this without orientation. \$\endgroup\$ – jokoon Mar 27 '13 at 12:47
  • \$\begingroup\$ @jokoon It doesn't have to. Essentially you'll just have instantaneous rotation. This is easier to implement than steering with orientation. \$\endgroup\$ – MichaelHouse Mar 27 '13 at 14:01
  • \$\begingroup\$ How do I steer with box2d ? \$\endgroup\$ – jokoon Mar 27 '13 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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