Tuesday, December 21, 2010

AI - Flocking Behavior

Flocking is a popular term in AI field and it indicates the behavior of a group of birds flying on the sky. Originally it is simulated on a computer by Craig Reynolds in 1986. For more information about flocking's history, you can wiki it out :)

Birds are smart, while they are flying, they won't "crash" with each other. Craig Reynolds named those birds as boids in his simulation program.

This behaviors is very useful when you are simulating a group of units moving to certain target.

Since my current game needed flocking behaviors so I need to learn how to implement it!

Luckily I found an useful tutorials:

In short, you just need 3 main rules to achieve flocking effect:
1) Boids try to fly towards the centre of mass of neighbouring boids.
2) Boids try to keep a small distance away from other objects.
3) Boids try to match velocity with near boids.


Sample screenshots:
* Just initialized

*Pursuing the target

*Target changed

Video demo:



Download link here:
PS: It's in XNA 4.0, so you need to install XNA redistributable 4.0 before you can run it.

No comments:

Post a Comment