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 have ~20 or more enemies and they need to follow a target and avoid to go on top of themselves. I mean follow a target and avoid to collide with each other. Area, on which they are walking, is just a rectangle plane in 2D space. What would be the most simple and efficient algorithm for this? Thanks.

share|improve this question
    
Closely related: gamedev.stackexchange.com/questions/2497/… –  Byte56 Jun 26 '13 at 13:24
add comment

2 Answers

up vote 10 down vote accepted

This is frequently referred to as flocking or a boids simulation. It's an algorithm that combines three behaviors to simulate the motion of a group:

enter image description here Separation: steer to avoid crowding local flockmates enter image description here Alignment: steer towards the average heading of local flockmates enter image description here Cohesion: steer to move toward the average position of local flockmates

The combination of those three will create a good approximation of a group moving together. These behaviors are described well in the GDC99 paper Steering Behaviors For Autonomous Characters (Craig W. Reynolds). Additionally there's a few Java demos of flocking and some other steering behaviors in action here. The other behaviors include a path following steering behavior and a follow the leader behavior that can be useful to you for having a group move along a path.

share|improve this answer
1  
Very good explanation, and the pictures are helpful. +1 –  feralin Jun 26 '13 at 17:49
add comment

I think you want steering behaviors, specifically Flocking. This enables you to have entities that will flock towards a certain point / target - if you can combine this with Avoidance behaviors you should be able to achieve what you want.

share|improve this answer
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.