Esempio n. 1
0
        private Vector3 AlignmentRule(BoidBehavior b) //calculates the alignment for boids.
        {                                             //Boid Rule Three: Alignment
            var pv = Vector3.zero;                    //pv variable equals a new vector3 vector

            foreach (var bj in _boids)                //for each bj variable in boids...
            {
                if (bj != b)                          //if the bj value does not equal b...
                {
                    pv += bj.Velocity;                //add the velocity of bj to pv
                }
            }

            pv = pv / (_boids.Count - 1);         //divid pv by the number of boids.
            return((pv - b.Velocity).normalized); //return the normalized value of pv minus the velocity of b
        }