Game Development Reference
In-Depth Information
if(go != this.gameObject)
{
dist =
Vector3.Distance(go.transform.
position,
this.transform.position);
if(dist < = neighbourDistance)
{
vcentre += go.transform.position;
groupSize++;
gSpeed = gSpeed +
go.GetComponent("flock").speed;
}
}
}
if(groupSize)
{
vcentre = vcentre/groupSize;
speed = gSpeed/groupSize;
...
}
}
Step 8. Play. Averaging of the speed will help keep the formed flocks
together.
Step 9. Finally, adding the third rule will enable the birds to keep out of
each other's way. Before changing the code, observe the current flocking
movement. Once a bird is flying in a circular pattern within the flock it
stays with that pattern. Now change the flock script to that in Listing 5.18 .
Listing 5.18 Adding Avoiding Behavior to Flocking Script
function ApplyRules()
{
...
for (var go : GameObject in gos)
{
if(go != this.gameObject)
{
dist = Vector3.Distance(go.transform.position +
this.transform.position);
if(dist < = neighbourDistance)
{
vcentre += go.transform.position;
groupSize++;
Search Nedrilad ::




Custom Search