Game Development Reference
In-Depth Information
Listing 5.15 Starting Script for Flocking
var speed: float = 0.001;
private var rotationSpeed: float = 5.0;
var averageHeading: Vector3;
var averagePosition: Vector3;
private var neighbourDistance = 2.0;
function Start()
{
speed = Random.Range(0.1,1);
}
function Update ()
{
transform.Translate(0, 0, Time.deltaTime * speed);
}
Listing 5.16 Script to Make Seagulls Move to the Average
Location of Their Neighbors
var speed: float = 0.001;
...
function Update ()
{
if(Random.Range(0,5) < 1)
ApplyRules();
transform.Translate(0, 0, Time.deltaTime * speed);
}
function ApplyRules()
{
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("Seagull");
var vcentre: Vector3;
var vavoid: Vector3;
var gSpeed: float;
//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(go != this.gameObject)
{
dist =
Vector3.Distance(go.transform.
position,
Search Nedrilad ::




Custom Search