Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CO3301 - Games Development 2 Week 22 Flocking Gareth Bellaby.

Similar presentations


Presentation on theme: "1 CO3301 - Games Development 2 Week 22 Flocking Gareth Bellaby."— Presentation transcript:

1 1 CO3301 - Games Development 2 Week 22 Flocking Gareth Bellaby

2 2 Introduction Flocking is a way of generating realistic movement for animals in a group: a flock. For example a flock of birds. Can be applied to non-human animals such as birds and fish. Can be extended and applied to aircraft, units and squads. Flocking was developed by Craig Reynolds.

3 3 Application to Games Flocking is of interest to games for two main reasons: Realistic flocks of birds or other animals which can be placed within a game world and just left to their own devices, e.g. a flock of birds that fly around, perch and react to the characters presence but without the need for scripting. Application to group movement.

4 4 Characteristics Flocking is an example of emergent behaviour. The individual members of the flock do not know anything about the behaviour of the flock. The flock will turn without direction. In the original formulation of flocking there is no leader. The movement propagates though the flock. An example of complexity out of simplicity - uses three simple rules.

5 5 Original Formulation Three rules: Separation: steer to avoid crowding local members of the flock. Alignment: steer towards the average heading of local members of the flock. Cohesion: steer to move toward the average position of members of the flock.

6 6 Discussion Only takes local members of the flock into account. The system is unpredictable (over moderate time periods. The algorithm uses feedback mechanisms. Feedback is when part (or all) of the output of a system is used as input into the system, e.g. a thermostat. Positive feedback leads to an uncontrolled system. Negative feedback leads to a controlled system. The system is chaotic. However, the use of feedback leads to group behaviour and, in most circumstances, a stable system.

7 7 Efficiency considerations An individual knows the average location and heading of other members of the flock, plus the distance between itself and the other members. The algorithm can be computationally expensive since each member needs to make a comparison against every other members. Can reduce this cost if the members are kept sorted by location.

8 8 Distances In Craig's initial experiments attraction and repulsion were weighted linearly by distance. This resulted in an unrealistic "bouncy" flocking action. The net effect is like a spring. He revised the model to use an inverse square of the distance. This resulted in more realistic flocking behaviour. The inverse square law dampens the effect.

9 9 Inverse Square Law The inverse square law is the law that an effect is inversely proportion to the square of the distance. For example, let the repulsive effect of the flock members at a distance of 1 be r : distancecalculationeffect 11/1 2 = 1r/1 21/2 2 = 1/4r/4 31/3 2 = 1/9r/9

10 10 Collisions Collisions will occur within the flock. There will come points where the net effect of the repulsors and attractors will force a collision between flock members. It is necessary to maintain a collision detection system in place. Could abrupt turns in emergency situations. It can be argued that this is realistic, e.g. birds do occasionally collide.

11 11 Forward perception Can introduce forward perception. The individual can only perceive those members of the flock who are in their field of view. A wide field of view leads to a broad flock. A narrow field of view leads to a narrow flock (ultimately follow-my- leader)

12 12 Behaviour As you change the values used with separation, alignment and cohesion the behaviour of the flock will change. Could give each member of the flock slightly different values, i.e. a flock made out of non-uniform members.

13 13 Graceful obstacle avoidance The flocking behaviour as described ignores obstacles. A graceful form of obstacle avoidance can be created by providing the individual with sensors. This has similarities with the sensors used in robotics.

14 14 Graceful obstacle avoidance Use a vector drawn from the individual to the outside of the radius. May be able to get away with just a single sensor sticking out of the front of the individual.

15 15 Leaders The original formulation of flocking did not include targets or leaders. The leader could be permamently designated. The designation of leader could be temporary. For example, let's introduce the idea of the flock aiming towards the most recent mouse click on screen. The leader could be the member of the flock nearest the target and where the target is in front of the individual. The rest of the flock could use a follow-the-leader rule.

16 16 Attractors and Repulsors These 3 rules describe 3 attractors/repulsors. Attractors attract the individual. Repulsors repulse the individual. The repulsors and attractors are summed together to generate the action.

17 17 Attractors and Repulsors The use of the inverse square law helps to dampen oscillation. However, it is inefficient to let the influence exerted by each member of the flock just degrade over distance since they will still exert an influence. It is necessary to introduce a cut-off as well.

18 18 Attractors and Repulsors The flock is in constant motion. If you want to allow the flock to come to rest then it may prove to use further dampening or allow more complex combination of forces, e.g. so that a flock of birds can come to rest when they perch. The aim is allow still points to arise automatically. Could tie the repulsion between flock members in with the speed of the members - although this would have to be a non-linear relationship (similar sort of reasoning to the inverse square used more generally in flocking).

19 19 More behaviour Predator - prey relationships can be created. Predators are to be avoided. A predator is repulsive. The individual will attempt to move away from a predator. Prey is to be hunted. The prey is attractive. A predator will attempt to close with prey. Note that real predators may utilise the natural response of their prey in order to trap them, e.g. wolves.

20 20 Formations Previously talked about the use of relative positioning in a formation. This can be used with flocking as well.

21 21 Attractors and Repulsors Lots more to explore. Olsen, "Attractors and Repulsors", Game Programming Gems 4, discusses the summation of attractors and repulsors. He also introduces a "mass" into the equation. The net effect of the "mass" would be to dampen the acceleration. Olsen also discusses some alternative non-linear attraction curves.

22 22 Some references Craig Reynolds (1987), "Flocks, Herds, and Schools: A Distributed Behavioral Model", SIGGRAPH http://www.red3d.com/cwr/papers/1987/boids.html Bourg & Seemann, AI for Game Developers. Sample chapter: http://www.gamecareerguide.com/features/282/book_exc erpt_ai_for_game_developers.php Steve Rabin, "Common Game AI Techniques", AI Game Programming Wisdom 2, 2003.

23 23 Some references Steven Woodcock, "Flocking with Teeth: Predators and Prey", Game Programming Gems 2, 2001. John M. Olsen, "Attractors and Repulsors", Game Programming Gems 4, 2004.


Download ppt "1 CO3301 - Games Development 2 Week 22 Flocking Gareth Bellaby."

Similar presentations


Ads by Google