Example #1
0
    public Agent GetNearestAliveEnemy(Vector3 start, Vector3 end, float radius, Agent ignoreAgent)
    {
        float len;
        float nearestLen = radius;
        Agent best       = null;

        //          Debug.Log("start " + start.ToString() + " end " + end.ToString());

        //if (ignoreAgent.debugGOAP) Debug.DrawLine(start, end);
        for (int i = 0; i < _Enemies.Count; i++)
        {
            Agent e = _Enemies[i];

            if (e == ignoreAgent)
            {
                continue;
            }

            // Debug.Log("testing enemy " + e.name + " : " + e.Position.ToString());
            if (e.IsAlive == false)
            {
                continue;
            }

            if (e.IsVisible == false)
            {
                continue;
            }

            len = Mathfx.DistanceFromPointToVector(start, end, e.Position);

            //  Debug.Log("Distance is " + len.ToString());

            if (len < nearestLen)
            {
                //if (ignoreAgent.debugGOAP) Debug.DrawLine(ignoreAgent.Position, e.Position);
                nearestLen = len;
                best       = e;
            }
        }

        return(best);
    }
Example #2
0
    public Agent1 GetNearestAgent(Vector3 lineStart, Vector3 lineEnd, float radius,
                                  List <Agent1> agents, bool ignoreSameGroup = false, AgentType agentType = AgentType.NONE)
    {
        float  len;
        float  nearestLen = radius;
        Agent1 best       = null;

        for (int i = 0; i < agents.Count; i++)
        {
            Agent1 e = agents[i];

            if (e == Agent)
            {
                continue;
            }

            if (ignoreSameGroup && e.group == Agent.group)
            {
                continue;
            }

            if (e.BlackBoard.IsAlive == false)
            {
                continue;
            }

            if (agentType != AgentType.NONE && agentType != e.agentType)
            {
                continue;
            }

            len = Mathfx.DistanceFromPointToVector(lineStart, lineEnd, e.Position);
            if (len < nearestLen)
            {
                nearestLen = len;
                best       = e;
            }
        }

        return(best);
    }