Unity Artificial Intelligence Programming , Fourth Edition by Davide Aversa

Unity Artificial Intelligence Programming , Fourth Edition by Davide Aversa

Author:Davide Aversa
Language: eng
Format: epub
Tags: COM012040 - COMPUTERS / Programming / Games, COM060080 - COMPUTERS / Web / General, COM051310 - COMPUTERS / Programming Languages / C#
Publisher: Packt
Published: 2019-04-24T07:49:32+00:00


This is the initialization method for our boid:

void Start () { randomFreq = 1.0f / randomFreq; //Assign the parent as origin origin = transform.parent; //Flock transform transformComponent = transform; //Temporary components Component[] tempFlocks= null; //Get all the unity flock components from the parent //transform in the group if (transform.parent) { tempFlocks = transform.parent.GetComponentsInChildren <UnityFlock>(); } //Assign and store all the flock objects in this group objects = new Transform[tempFlocks.Length]; otherFlocks = new UnityFlock[tempFlocks.Length]; for (int i = 0;i<tempFlocks.Length;i++) { objects[i] = tempFlocks[i].transform; otherFlocks[i] = (UnityFlock)tempFlocks[i]; } //Null Parent as the flock leader will be //UnityFlockController object transform.parent = null; //Calculate random push depends on the random frequency //provided StartCoroutine(UpdateRandom()); }

We set the parent of the object of our boid as origin, meaning that this will be the controller object for the other boids to follow. Then, we grab all the other boids in the group and store them in our own variables for later reference.

The StartCoroutine method starts the UpdateRandom() method as a coroutine:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.