public Vector3 Alignment(Boid b)
        {
            if (Neighbors(b).Count <= 1)
            {
                return(Vector3.zero);
            }
            var alignmentForce = Vector3.zero;

            foreach (var neighbor in Neighbors(b))
            {
                if (neighbor == b)
                {
                    continue;
                }
                alignmentForce += neighbor.Velocity;
            }
            alignmentForce /= Neighbors(b).Count - 1;

            return((alignmentForce - b.Velocity) / 8);
        }
        public Vector3 Cohesion(Boid b)
        {
            if (Neighbors(b).Count <= 1)
            {
                return(Vector3.zero);
            }
            var cohesionForce = Vector3.zero;

            foreach (var neighbor in Neighbors(b))
            {
                if (neighbor == b)
                {
                    continue;
                }
                cohesionForce += neighbor.Position;
            }
            cohesionForce /= Neighbors(b).Count - 1;

            return((cohesionForce - b.Position) / 100);
        }
        public Vector3 Dispersion(Boid b)
        {
            if (Neighbors(b).Count <= 0)
            {
                return(Vector3.zero);
            }
            var seperationForce = Vector3.zero;

            foreach (var neighbor in Neighbors(b))
            {
                if (neighbor == b)
                {
                    continue;
                }
                var dist = Vector3.Distance(b.Position, neighbor.Position);
                if (dist < 10f)
                {
                    var dir = (b.Position - neighbor.Position).normalized;
                    seperationForce += dir;
                }
            }
            return(seperationForce);
        }
Exemplo n.º 4
0
 public void SetBoid(Boid b)
 {
     agent = b;
 }