Game Development Reference
In-Depth Information
{
...
}
if(groupSize)
{
vcentre = vcentre/groupSize + wind;
speed = gSpeed/groupSize;
...
}
}
Step 12. Play. The added wind vector will cause the birds to fly along
the same course. The birds will still flock together, but instead of
circling they will form close-streamed groups.
Step 13. If you want the birds to fly across the screen to a particular
location, a goal position can also be added to the rules. Modify
the flock script to that in Listing 5.20 .
Listing 5.20 Directing Flock to Fly to a Specific Location
function ApplyRules()
{
...
var wind: Vector3 = new Vector3(1,0,1);
var goalPos:Vector3 = new Vector3(10,0,10);
var dist: float;
var groupSize: int = 0;
for (var go : GameObject in gos)
{
...
}
if(groupSize)
{
vcentre = vcentre/groupSize +
wind + (goalPos this.transform.
position);
speed = gSpeed/groupSize;
...
}
}
Step 14. Play. The birds will form into groups flying toward a single
goal location.
Search Nedrilad ::




Custom Search