void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == gameObject.tag) { BoidAI otherBoid = other.GetComponentInChildren <BoidAI>(); if (CanFlock(otherBoid)) { neighbor.Add(otherBoid); } } }
void OnTriggerExit2D(Collider2D other) { if (other.gameObject.tag == gameObject.tag) { BoidAI otherBoid = other.GetComponentInChildren <BoidAI>(); if (otherBoid) { neighbor.Remove(otherBoid); } } }
bool CanFlock(BoidAI other) { if (other) { if (other.Team == team && !neighbor.Contains(other)) { return(true); } } return(false); }
Quaternion averageFlockHeading() { Vector3 sumVector = Vector3.zero; foreach (GameObject boid in visibleFlock) { BoidAI boidAI = boid.GetComponent <BoidAI>(); Quaternion boidRotaion = boidAI.getRotation(); sumVector += boidRotaion.eulerAngles; } sumVector += this.getRotation().eulerAngles; Vector3 avgVector = sumVector / (visibleFlock.Count + 1); return(Quaternion.Euler(avgVector)); }
//Methods public void OnNeighborDestroy(BoidAI boid) { neighbor.Remove(boid); }