Exemple #1
0
    GameObject closestVisibleMate()
    {
        // find nearby things!
        Collider[] nearbyObjects = Physics.OverlapSphere(rb.position, genome["sightRange"].value());
        // find closest thing
        float      minDist      = 10000000000f;
        GameObject nearestThing = null;

        foreach (Collider c in nearbyObjects)
        {
            Omnivore mate = c.gameObject.GetComponent <Omnivore>();
            // Not all gameObjects are even Omnivores
            if (mate != null)
            {
                // Not all omnivores are the right sex, and not all of them are frisky
                if (mate.getSex() == -1 || mate.getSex() == this.getSex() || mate.getMode() != "frisky")
                {
                    mate = null;
                }
            }
            if (mate != null)
            {
                float dist = Vector3.Distance(rb.position, c.gameObject.transform.position);
                if (dist < minDist & c.gameObject != gameObject)
                {
                    minDist      = dist;
                    nearestThing = c.gameObject;
                }
            }
        }
        return(nearestThing);
    }
Exemple #2
0
    bool FixedUpdateFrisky()
    {
        GameObject target = closestVisibleMate();

        if (target == null)
        {
            return(false);
        }
        Omnivore mate = target.GetComponent <Omnivore>();

        if (Vector3.Distance(rb.position, target.transform.position) > size + 0.01)
        {
            Vector3 move = Vector3.MoveTowards(rb.position, target.transform.position, genome["walkspeed"].value());
            rb.MovePosition(move);
        }
        else
        {
            // Do the nasty
            if (mate.getMode() == "frisky" && this.getSex() == 0)
            {
                createOffspring(mate);
            }
        }
        return(true);
    }