Exemplo n.º 1
0
    private Vertex findLastPoint()
    {
        CrossPrevList crossPrevList = queueOfNodes[queueOfNodes.Count - 1];
        Vertex        node          = graph.Find(i => i.getName().Equals(crossPrevList.Name));
        List <Edge>   edgeList      = node.getEdgeList();
        Vertex        nextPoint     = null;

        foreach (Edge edge in edgeList)
        {
            var start  = edge.getStartV();
            var target = edge.getEndV();

            bool direction = (start.getCordX() - target.getCordX()) == 0 ? false : true; // false -> z, true -> x

            var player = GameObject.Find("Player").transform.position;

            if (direction)
            {
                if (Math.Round(maxMin(start, target, true)[0].getCordX(), 1) < Math.Round(player.x, 1) &&
                    Math.Round(maxMin(start, target, true)[1].getCordX(), 1) > Math.Round(player.x, 1))
                {
                    nextPoint = graph.Find(i => i.getName().Equals(target.getName()));
                }
            }
            else
            {
                if (Math.Round(maxMin(start, target, false)[0].getCordZ(), 1) < Math.Round(player.z, 1) &&
                    Math.Round(maxMin(start, target, false)[1].getCordZ(), 1) > Math.Round(player.z, 1))
                {
                    nextPoint = graph.Find(i => i.getName().Equals(target.getName()));
                }
            }
        }
        return(nextPoint);
    }
Exemplo n.º 2
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.name.Contains("crossTags"))
        {
            bool isValid = CrossPrevList.checkValidCross(queueOfNodes, other.name);

            if (!isValid)
            {
                CrossPrevList cross = new CrossPrevList(other.transform.position.x, other.transform.position.z, other.name);
                queueOfNodes.Add(cross);

                Vertex player = new Vertex(getEnemyCloseCross().getName());
                Vertex enemy  = new Vertex(other.name);
                path = dijkstraPath(enemy, player);

                if (path.Count == 1)
                {
                    isPathOne = true;
                }
                else
                {
                    isPathOne = false;
                }
            }



            if (firstCross)
            {
                nextPosition = new Vector3(other.transform.position.x, other.transform.position.y, other.transform.position.z);
            }
        }
    }