Пример #1
0
        private Vector2 Cohesion(Boid boid)
        {
            Vector3 pcJ = Vector3.zero;

            /*foreach (Boid b in flock) {
             *  if (b != boid) {
             *      pcJ = pcJ + b.transform.position;
             *  }
             * }*/
            for (int i = 0; i < flock.Count; i++)
            {
                if (flock[i] != boid)
                {
                    pcJ = pcJ + flock[i].transform.position;
                }
            }

            pcJ = pcJ / (flock.Count - 1);

            return((pcJ - boid.transform.position) / 100);
        }
Пример #2
0
        private Vector3 BoundPosition(Boid boid)
        {
            Vector3 v = Vector3.zero;

            if (boid.transform.position.x < xMin - buffer)
            {
                v.x = xMax;
            }
            else if (boid.transform.position.x > xMax + buffer)
            {
                v.x = xMin;
            }

            if (boid.transform.position.y < yMin - buffer)
            {
                v.y = yMax;
            }
            else if (boid.transform.position.y > yMax + buffer)
            {
                v.y = yMin;
            }
            return(v);
        }