Game Development Reference
if(dist < = neighbourDistance)
vcentre += go.transform.position;
vcentre = vcentre/groupSize;
var direction = vcentre — transform.position;
if(direction != Vector3.zero)
rotationSpeed * Time.
Step 6. Play. Small flocks will form in the population. In the script,
Random.Range is used to apply the rules about one in five game
loops. This ensures that not all the birds have the rules that run each
game loop. If this happens, the application runs very slowly and gets
slower the more birds you have. Note that the average position is also
only determined for neighboring birds, not the whole population. This
is determined by the neighbourDistance variable. If you make this
value larger, you will get one big flock.
Step 7. Currently, because the birds have random speeds, birds will
eventually break away from their flocks because they can't keep up or
are going too fast. To keep them together, the second rule is applied.
Birds in the flock match the average speed. To achieve this, modify the
flock script to that in Listing 5.17 .
Listing 5.17 Applying an Average Speed to a Flock
for (var go : GameObject in gos)