Example #1
0
    // Update is called once per frame
    void Update()
    {
        //Eat mechanism
        Collider[] foods = Physics.OverlapSphere(this.transform.position, 3f);
        foreach (Collider food in foods)
        {
            if (food.gameObject.tag == "Food")
            {
                fullness += 10;
                food foodScript = food.GetComponent <food>();
                foodScript.die();
            }
            else if (food.gameObject.tag == "Death")
            {
                Die();
            }
        }



        if (targetedFood == null)
        {
            Debug.Log("Checking for food");
            Collider[] foodsSee = Physics.OverlapSphere(this.transform.position, 60f);
            foreach (Collider food in foodsSee)
            {
                if (food.gameObject.tag == "Food")
                {
                    targetedFood = food.gameObject;
                }
            }
        }



        //Input the variables to the brain to generate the movement
        if (targetedFood != null)
        {
            List <float> input = new List <float> {
                1f, targetedFood.transform.position.x - transform.position.x, targetedFood.transform.position.z - transform.position.z, health, fullness, fatness
            };
            List <float> XMovement     = Brain(XThetas, input);
            List <float> ZMovement     = Brain(ZThetas, input);
            List <float> SpeedMovement = Brain(SpeedThetas, input);
            List <float> XRotate       = Brain(XRotThetas, input);
            //Debug.Log(XMovement[0].ToString() + ":" + ZMovement[0].ToString() + ":" + SpeedMovement[0].ToString() + ":" + XRotate[0].ToString());


            move(XMovement[0] * Time.deltaTime, ZMovement[0] * Time.deltaTime, Maths.ReLu(SpeedMovement[0]) * Time.deltaTime, XRotate[0]);
        }
    }