Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm using box2d (the c++ one).

I found a method for an arriving behavior (on http://www.red3d.com/cwr/steer/gdc99/ ), which works well, problem is, the bodies are bumping into each other and it results in an ugly shaking effect.

How do you make sure bodies keep away from each other after I applied the arriving behavior ? Or the other way around ?

I'm wondering if it might be a better idea to completely remove the arriving behavior to implement the separate algorithm.

edit: even setting a low restitution results in shaking

share|improve this question
    
done ! yes they're individuals –  jokoon May 8 '13 at 11:26
    
Have you considered just making them repel each other, like with a magnetic field? (Similar things are discussed under "separation" on the page you linked.) –  Anko May 8 '13 at 11:30
    
good idea, but no, but I wonder how I can do that with box2d, it would require to make queries for bodies around each one, aren't queries expensive ? –  jokoon May 8 '13 at 14:43
add comment

1 Answer

Each body finds the bodies closest to it. It then attempts to steer away from the sum of the neighbors. The closer a neighbor is, the more it adds to the repel force.

enter image description here

If each body does this, they will spread out away from each other. This combined with a cohesion algorithm keeps the bodies grouped, but not on top of each other.

enter image description here

Both of these are covered in the link you shared.

share|improve this answer
    
question is, how do you find the "closest" bodies ? I guess it requires a query of some sort. –  jokoon May 8 '13 at 14:46
    
If you don't have too many bodies, looping through all of them measuring the distance should work perfectly. If you're worried about performance, I don't think measuring distances is that performance intense. –  Andre May 8 '13 at 14:51
1  
There are questions on finding the nearest and questions about optimizing it. Use one of the methods mentioned in those answers to organize pointers to your bodies. Then you can quickly find the nearest bodies when doing separation and cohesion. –  Byte56 May 8 '13 at 15:05
add comment

Your Answer

 
discard

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.