Example #1
0
    public override Vector3 Execute(AutonomousAgent agent, AutonomousAgent target, string targetTag)
    {
        Vector3 steering = Vector3.zero;

        //get all agent game objects within perception radius
        GameObject[] gameObjects = AutonomousAgent.GetGameObjects(gameObject, targetTag, perception);
        if (gameObjects.Length > 0)
        {
            //get center of all agents in perception
            Vector3 sum = Vector3.zero;
            foreach (GameObject gameObject in gameObjects)
            {
                AutonomousAgent targetAgent = (gameObject) ? target.GetComponent <AutonomousAgent>() : null;
                Vector3         direction   = agent.position - targetAgent.position;
                float           distance    = direction.magnitude;

                direction = direction.normalized;
                direction = direction / distance;

                sum = sum + direction;
            }

            Vector3 desired = sum.normalized * agent.maxSpeed;
            steering = desired - agent.velocity;
        }

        return(steering);
    }
Example #2
0
    public override Vector3 ExecuteOrder66(AutonomousAgent agent, AutonomousAgent target, string targetTag = "")
    {
        Vector3 steering = Vector3.zero;

        //get all agent game objects within perception radius
        GameObject[] gameObjects = AutonomousAgent.GetGameObjects(gameObject, targetTag, perception);

        if(gameObjects.Length > 0)
        {
            //get center position of all agents within perception
            Vector3 sum = Vector3.zero;
            foreach(GameObject gameObject in gameObjects)
            {
                AutonomousAgent targetAgent = (gameObject) ? gameObject.GetComponent<AutonomousAgent>() : null;
                sum = sum + targetAgent.position;
            }
            sum = sum / gameObjects.Length;

            //seek to center position
            Vector3 desired = (sum - agent.position).normalized * agent.maxSpeed;
            steering = desired - agent.velocity;

        }

        return steering;
    }
Example #3
0
    public override Vector3 Execute(AutonomousAgent agent, AutonomousAgent target, string targetTag)
    {
        Vector3 steering = Vector3.zero;

        GameObject[] gameObjects = AutonomousAgent.GetGameObjects(gameObject, targetTag, perception);
        if (gameObjects.Length > 0)
        {
            Vector3 sum = Vector3.zero;
            foreach (GameObject gameObject in gameObjects)
            {
                AutonomousAgent targetAgent = (gameObject) ? gameObject.GetComponent <AutonomousAgent>() : null;
                sum = sum + targetAgent.position;
            }
            sum = sum / gameObjects.Length;

            Vector3 desired = (sum - agent.position).normalized * agent.maxSpeed;
            steering = desired - agent.velocity;
        }

        return(steering);
    }
Example #4
0
    public override Vector3 Execute(AutonomousAgent agent, AutonomousAgent target, string targetTag)
    {
        Vector3 steering = Vector3.zero;

        //get all agent game objects within perception radius
        GameObject[] gameObjects = AutonomousAgent.GetGameObjects(gameObject, targetTag, perception);
        if (gameObjects.Length > 0)
        {
            //get center of all agents in perception
            Vector3 sum = Vector3.zero;
            foreach (GameObject gameObject in gameObjects)
            {
                AutonomousAgent targetAgent = (gameObject) ? target.GetComponent <AutonomousAgent>() : null;
                sum = sum + targetAgent.velocity;
            }
            Vector3 averageVelocity = sum / gameObjects.Length;

            //allign to average velocity position
            Vector3 desired = averageVelocity.normalized * agent.maxSpeed;
            steering = desired - agent.velocity;
        }

        return(steering);
    }