예제 #1
0
    private Vector3 Separation()
    {
        //empty our lists
        nearVillagers.Clear();
        nearVillagersDistances.Clear();

        //method variables
        Vector3 dv  = new Vector3();        // the desired velocity
        Vector3 sum = new Vector3();

        for (int i = 0; i < gameManager.Villagers.Count; i++)
        {
            //retireves distance between two flockers of reference numbers
            // findFlocker and i

            GameObject villager = gameManager.Villagers[i];

            float dist = Vector3.Distance(this.transform.position, gameManager.Villagers[i].transform.position);

            if (dist < 10.0 && dist != 0)
            {
                dv = this.transform.position - villager.transform.position;

                dv.Normalize();

                dv   = dv * ((1.0f / dist));
                sum += dv;
            }
        }

        float dist2 = Vector3.Distance(this.transform.position, gameManager.Mayor.transform.position);

        if (dist2 <= 10.0 && dist2 != 0)
        {
            dv = this.transform.position - gameManager.Mayor.transform.position;

            dv.Normalize();

            dv = dv * ((1.0f / dist2));

            sum += dv;
        }


        //sum.Normalize();
        //sum = sum * (steering.maxSpeed);
        sum = sum - this.steering.Velocity;

        return(steering.AlignTo(sum));
    }