In I made a computer model of coordinated animal motion such as bird flocks and fish schools. It was based on three dimensional computational geometry of the sort normally used in computer animation or computer aided design. I called the generic simulated flocking creatures boids. The basic flocking model consists of three simple steering behaviors which describe how an individual boid maneuvers based on the positions and velocities its nearby flockmates:. Each boid has direct access to the whole scene's geometric description, but flocking requires that it reacts only to flockmates within a certain small neighborhood around itself. The neighborhood is characterized by a distance measured from the center of the boid and an angle, measured from the boid's direction of flight.
|Genre:||Health and Food|
|Published (Last):||12 August 2014|
|PDF File Size:||20.13 Mb|
|ePub File Size:||2.93 Mb|
|Price:||Free* [*Free Regsitration Required]|
Often in video games, nonplayer characters must move in cohesive groups rather than independently. Your sheep would appear more realistic if they were grazing in a flock rather than walking around aimlessly. Here again, birds that hunt in flocks rather than independently would seem more realistic and pose the challenge to the player of dealing with somewhat cooperating groups of predators.
These examples of local fauna moving, grazing, or attacking in herds or flocks might seem like obvious ways in which you can use flocking behavior in games. With that said, you do not need to limit such flocking behavior to fauna and can, in fact, extend it to other nonplayer characters. For example, in a real-time strategy simulation, you can use group movement behavior for nonplayer unit movement.
These units can be computer-controlled humans, trolls, orcs, or mechanized vehicles of all sorts. In a combat flight simulation, you can apply such group movement to computer-controlled squadrons of aircraft. In a first-person shooter, computer-controlled enemy or friendly squads can employ such group movement. You even can use variations on basic flocking behavior to simulate crowds of people loitering around a town square, for example. In all these examples, the idea is to have the nonplayer characters move cohesively with the illusion of having purpose.
This is as opposed to a bunch of units that move about, each with their own agenda and with no semblance of coordinated group movement whatsoever. Craig Reynolds coined the term boids when referring to his simulated flocks. The behavior he generated very closely resembles shoals of fish or flocks of birds. All the boids can be moving in one direction at one moment, and then the next moment the tip of the flock formation can turn and the rest of the flock will follow as a wave of turning boids propagates through the flock.
Even more impressive is the fact that this behavior is the result of three elegantly simple rules. These rules are summarized as follows:. Have each unit steer so as to align itself to the average heading of its neighbors.
In physically simulated, continuous environments, you can steer by applying steering forces on the units being simulated. Here you can apply the same technique we used in the chasing, evading, and pattern movement examples earlier in the book.
Refer to Chapter 2 and, specifically, to Figure and surrounding discussion to see how you can handle steering. Treating the units as rigid bodies enables you to take care of orientation. For tiled environments, you can employ the line-of-sight methods we used in the tile-based chasing and evading examples to have the units steer, or rather, head toward a specific point. To what extent is each unit aware of its neighbors?
Basically, each unit is aware of its local surroundings—that is, it knows the average location, heading, and separation between it and the other units in the group in its immediate vicinity. The unit does not necessarily know what the entire group is doing at any given time. Figure illustrates a unit the bold one in the middle of the figure with a visibility arc of radius r around it. The unit can see all other units that fall within that arc.
The visible units are used when applying the flocking rules; all the other units are ignored. Both parameters affect the resulting flocking motion, and you can tune them to your needs. In general, a large radius will allow the unit to see more of the group, which results in a more cohesive flock.
That is, the flock tends to splinter into smaller flocks less often because each unit can see where most or all of the units are and steer accordingly. On the other hand, a smaller radius tends to increase the likelihood of the flock to splinter, forming smaller flocks.
A flock might splinter if some units temporarily lose sight of their neighbors, which can be their link to the larger flock. When this occurs, the detached units will splinter off into a smaller flock and could perhaps rejoin the others if they happen to come within sight again. Navigating around obstacles also can cause a flock to break up.
In this case, a larger radius will help the flock to rejoin the group. The widest field of view is, of course, degrees. Some flocking algorithms use a degree field of view because it is easier to implement; however, the resulting flocking behavior might be somewhat unrealistic.
A more common field of view is similar to that illustrated in Figure , where there is a distinct blind spot behind each unit. Here, again, you can tune this parameter to your liking. In general, a wide field of view, such as the one illustrated in Figure in which the view angle is approximately degrees, results in well formed flocks. A narrow field of view, such as the one illustrated in Figure in which the view angle is a narrow 45 degrees, results in flocks that tend to look more like a line of ants walking along a path.
Both results have their uses. For example, if you were simulating a squadron of fighter jets, you might use a wide field of view. If you were simulating a squad of army units sneaking up on someone, you might use a narrow field of view so that they follow each other in a line and, therefore, do not present a wide target as they make their approach.
If you combine this latter case with obstacle avoidance, your units would appear to follow the point man as they sneak around obstacles. For this simple demonstration, interaction with the environment consists of avoiding circular objects.
The flocking units interact with the player by chasing him. You can refer to Figure and the surrounding discussion to refresh your memory on the steering model.
This net steering force will point in either the starboard or port direction relative to the unit and will be the accumulation of steering forces determined by application of each flocking rule. This approach enables us to implement any number or combination of flocking rules—each rule makes a small contribution to the total steering force and the net result is applied to the unit once all the rules are considered.
We should caution you that this approach does require some tuning to make sure no single rule dominates. For example, if we make the steering force contribution from the cohesion rule overpower the others, and say we implement an obstacle avoidance rule so that units try to steer away from objects, if the cohesion rule dominates, the units might stay together. Therefore, they will be unable to steer around objects and might run into or through them.
Tuning will require trial and error. Modulating the steering forces will require that we write the steering force contribution from each rule in the form of an equation or response curve so that the contribution is not constant. Instead, we want the steering force to be a function of some key parameter important to the given rule.
Consider the avoidance rule for a moment. We want the avoidance rule steering force contribution to be small when the units are far away from each other, but we want the avoidance rule steering force contribution to be relatively large when the units are dangerously close to each other. This way, when the units are far apart, the cohesion rule can work to get them together and form a flock without having to fight the avoidance rule. Further, once the units are in a flock, we want the avoidance rule to be strong enough to prevent the units from colliding in spite of their tendency to want to stay together due to the cohesion and alignment rules.
Therefore, we want to write the avoidance steering force as a function of separation distance. You can use an infinite number of functions to accomplish this task; however, in our experience, a simple inverse function works fine. In this case, the avoidance steering force is inversely proportional to the separation distance.
Therefore, large separation distances yield small avoidance steering forces, while small separation distances yield larger avoidance steering forces. If that angle is small, we want to make only a small adjustment to its heading, whereas if the angle is large, a larger adjustment is required.
As we discussed earlier, each unit in a flock must be aware of its neighbors. Exactly how many neighbors each unit is aware of is a function of the field-of-view and view radius parameters shown in Figure Because the arrangement of the units in a flock will change constantly, each unit must update its view of the world each time through the game loop.
This means we must cycle through all the units in the flock collecting the required data. This neighbor search can become computationally expensive as the number of units grows large. The sample code we discuss shortly is written for clarity and is a good place to make some optimizations.
This function is responsible for updating the positions of each unit and for drawing each unit to the display buffer. Example shows the UpdateSimulation function for this example.
UpdateSimulation performs the usual tasks. It clears the back buffer upon which the scene will be drawn; it handles any user interaction for the player-controlled unit; it updates the computer-controlled units; it draws everything to the back buffer; and it copies the back buffer to the screen when done.
The interesting part for our purposes is where the computer-controlled units are updated. For this task, UpdateSimulation loops through an array of computer-controlled units and, for each one, calls another function named DoUnitAI. All the flocking rules are implemented in this function. Notice here that the given unit, the one currently under consideration, is passed in as a parameter.
More specifically, an array index to the current unit under consideration is passed in to DoUnitAI as the parameter i. Example shows a snippet of the very beginning of DoUnitAI. This snippet contains only the local variable list and initialization code. This is the unit for which all the neighbor data will be collected and the flocking rules will be implemented. The variable, j , is used as the array index to all other units in the Units array. These are the potential neighbors to Units[i].
N represents the number of neighbors that are within view of the unit currently under consideration. Pave and Vave will hold the average position and velocity vectors, respectively, of the N neighbors. Fs represents the net steering force to be applied to the unit under consideration. Pfs represents the location in body-fixed coordinates at which the steering force will be applied.
Such quantities include relative position vectors and heading vectors in both global and local coordinates. InView is a flag that indicates whether a particular unit is within view of the unit under consideration.
DoFlock is simply a flag that indicates whether to apply the flocking rules. In this demo, you can turn flocking on or off. Further, you can implement three different visibility models to see how the flock behaves.
Finally, RadiusFactor represents the r parameter shown in Figure , which is different for each visibility model. After all the local variables are declared, several of them are initialized explicitly. As you can see in Example , they are, for the most part, initialized to 0.
Boids: Flocking made simple
Amazon: amazon. As usual, I started off my quest with some searches on trusty old Google, which brought up a number of intriguing results. As it turns out, there is a whole bunch of existing research on flocking birds and swarming insects, dating back to more than 30 years ago. One popular and well-known product of this research is the Boids algorithm created by Craig Reynolds in The Origin of Boids Boids is an artificial life program developed by Craig Reynolds to simulate the behavior of flocking birds.
AI for Game Developers by Glenn Seemann, David M Bourg
Often in video games, nonplayer characters must move in cohesive groups rather than independently. Your sheep would appear more realistic if they were grazing in a flock rather than walking around aimlessly. Here again, birds that hunt in flocks rather than independently would seem more realistic and pose the challenge to the player of dealing with somewhat cooperating groups of predators. These examples of local fauna moving, grazing, or attacking in herds or flocks might seem like obvious ways in which you can use flocking behavior in games. With that said, you do not need to limit such flocking behavior to fauna and can, in fact, extend it to other nonplayer characters. For example, in a real-time strategy simulation, you can use group movement behavior for nonplayer unit movement. These units can be computer-controlled humans, trolls, orcs, or mechanized vehicles of all sorts.
Craig Reynolds: boids flock
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together. If nothing happens, download GitHub Desktop and try again. Go back. If nothing happens, download Xcode and try again. If nothing happens, download the GitHub extension for Visual Studio and try again.