Esempio n. 1
0
    private Vector3 group()      //Make all the predators group up
    {
        Vector3 force = Vector3.zero;

        for (int i = 0; i < fc.predSize(); i++)
        {
            Predator pred = fc.getPred(i);
            if (fc.getPred(i) != this)
            {
                Vector3 delta     = pred.transform.position - transform.position;
                float   dist      = Vector3.Distance(pred.transform.position, transform.position);
                float   A         = 80f;      //Starting power
                float   B         = 10f;
                float   n         = 1.1f;     //How much it increases exponentially
                float   m         = -.01f;
                float   magnitude = -(A / Mathf.Pow(dist, n)) + (B / Mathf.Pow(dist, m));

                force += delta.normalized * magnitude;
            }
        }
        return(force);
    }
Esempio n. 2
0
    Vector3 avoid()       //Avoid all predators nearby
    {
        Vector3 force = Vector3.zero;
        int     count = 0;

        for (int i = 0; i < fc.predSize(); i++)
        {
            Predator pred = fc.getPred(i);
            if (pred)
            {
                float dist = Vector3.Distance(transform.position, pred.transform.position);
                if (dist < AVO_DIST)                   //Very similar to sep above
                {
                    count++;
                    force += (transform.position - pred.transform.position) / Mathf.Pow(dist, 2f);                    //Pointing away from them, and we want it to get exponentially stronger as they approach eachother.
                }
            }
        }
        if (count > 0)
        {
            force /= count;
        }
        return(force);
    }