示例#1
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.tag == gameObject.tag)
     {
         BoidAI otherBoid = other.GetComponentInChildren <BoidAI>();
         if (CanFlock(otherBoid))
         {
             neighbor.Add(otherBoid);
         }
     }
 }
示例#2
0
 void OnTriggerExit2D(Collider2D other)
 {
     if (other.gameObject.tag == gameObject.tag)
     {
         BoidAI otherBoid = other.GetComponentInChildren <BoidAI>();
         if (otherBoid)
         {
             neighbor.Remove(otherBoid);
         }
     }
 }
示例#3
0
    bool CanFlock(BoidAI other)
    {
        if (other)
        {
            if (other.Team == team && !neighbor.Contains(other))
            {
                return(true);
            }
        }

        return(false);
    }
示例#4
0
    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));
    }
示例#5
0
    //Methods

    public void OnNeighborDestroy(BoidAI boid)
    {
        neighbor.Remove(boid);
    }