//******************************************************************************************************************//
    //******************************************************************************************************************//

    // A decision to check if a health kit is in agent's sight
    public static bool IsHealthKitInSight(AgentActions agent, GameObject enemy, GameObject powerPickup, GameObject healthKit)
    {
        // If the game objects of HealthKit tag are in sight, the count
        // of the returned list will be greater than zero
        if (agent.GetGameObjectsInViewOfTag(Constants.HealthKitTag).Count > 0)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        //******************************************************************************************************************//
        //******************************************************************************************************************//

        // Setting the distance to infinity for
        // a default value
        closest_distance = Mathf.Infinity;

        // These will stay null if nothing of that type
        // is in sight
        enemy        = null;
        power_pickup = null;
        health_kit   = null;

        // We now get the perceived game objects of a particular tag
        // and store it to the list
        list_enemies       = agentScript.GetGameObjectsInViewOfTag(Constants.EnemyTag);
        list_power_pickups = agentScript.GetGameObjectsInViewOfTag(Constants.PowerUpTag);
        list_health_kits   = agentScript.GetGameObjectsInViewOfTag(Constants.HealthKitTag);

        //******************************************************************************************************************//
        //******************************************************************************************************************//

        for (int i = 0; i < list_enemies.Count; i++)
        {
            // If the enemy is alive and active, perform the distance check
            if (list_enemies[i].GetComponent <AgentActions>().Alive&& list_enemies[i] != null)
            {
                // If it's less than the closest distance, assign the individual object and
                // update the closest distance
                if (Vector3.Distance(list_enemies[i].transform.position, this.gameObject.transform.position) < closest_distance)
                {
                    enemy            = list_enemies[i];
                    closest_distance = Vector3.Distance(list_enemies[i].transform.position, this.gameObject.transform.position);
                }
            }
            // Else, remove it from the list
            else
            {
                list_enemies.Remove(list_enemies[i]);
            }
        }

        //******************************************************************************************************************//
        //******************************************************************************************************************//

        closest_distance = Mathf.Infinity;

        for (int i = 0; i < list_power_pickups.Count; i++)
        {
            if (list_power_pickups[i] != null)
            {
                if (Vector3.Distance(list_power_pickups[i].transform.position, this.gameObject.transform.position) < closest_distance)
                {
                    power_pickup     = list_power_pickups[i];
                    closest_distance = Vector3.Distance(list_power_pickups[i].transform.position, this.gameObject.transform.position);
                }
            }
            else
            {
                list_power_pickups.Remove(list_power_pickups[i]);
            }
        }

        //******************************************************************************************************************//
        //******************************************************************************************************************//

        closest_distance = Mathf.Infinity;

        for (int i = 0; i < list_health_kits.Count; i++)
        {
            if (list_health_kits[i] != null)
            {
                if (Vector3.Distance(list_health_kits[i].transform.position, this.gameObject.transform.position) < closest_distance)
                {
                    health_kit       = list_health_kits[i];
                    closest_distance = Vector3.Distance(list_health_kits[i].transform.position, this.gameObject.transform.position);
                }
            }
            else
            {
                list_health_kits.Remove(list_health_kits[i]);
            }
        }

        //******************************************************************************************************************//
        //******************************************************************************************************************//

        // If we're alive, continue
        if (agentScript.Alive)
        {
            // Gets the leaf action from the tree
            IAction action = decision_tree.Execute(agentScript, enemy, power_pickup, health_kit);

            action_executor.SetNewAction(action);
            action_executor.Execute(agentScript, enemy, power_pickup, health_kit);
        }

        //******************************************************************************************************************//
        //******************************************************************************************************************//
    }