![]() |
|
|
Flocking by Mike
The rules behind Boids are simple. Each member of the flock determines its own movements by considering four "steering behaviors" that are a function of the position, speed and heading of its surrounding flock mates and obstacles:
My simulation consists of two loops - one for calculating each Bot's steering behavior (the "sensing" loop) and the other to move each Bot accordingly (the "action" loop). An outline of the algorithm in pseudo code is shown below. The composite behavior referred to in the outline is the turn angle computed by combining the turn angles from the four steering behaviors. In computing the composite behavior, some steering behaviors should take precedence over others, for example, obstacle avoidance should be given the highest priority to avoid death by smashing into a wall or window. My simulation introduces an obstacle in the form of the position of mouse icon on the Screen display. This gives the observer a chance to interact with the simulation. The following pseudo code gives an idea of how the simulation proceeds.
A few other comments on the algorithm....I used the GroupNear method of the Bot object to collect local flock mates within a certain radius. The method returns a Group object which contains the local flock mates. The Group object has methods to calculate average direction and position of its members. Also, there is a good reason for needing two inner loops instead of just one. For each time step, the composite steering behavior of all Bots needs to be calculated and stored BEFORE any Bot is allowed to move. Using two inner loops synchronizes the Bots, allowing all to sense the local environment at the same instance, and then to simultaneously react to that sense. In order to store each Bot's composite steering behavior calculated in the sensing loop for use in the action loop, the composite behavior is stored using the Tags method of the Bot object. Any number of Tag objects can be added in order to attach information to each Bot - in essence serving as a Bot memory. Below is a screenshot showing a flock avoiding the mouse icon:
References:Craig Reynolds, "Flocks,
Herds, and Schools: A Distributed Behavioral Model", Back to projects main page <<prev project next project>>
|
||||||||||||||||||
|
||||||||||||||||||||
| Copyright © | This sited last updated Jan 05, 2008 |