Esempio n. 1
0
    IEnumerator FindPathAfter()
    {
        float      distance = Vector3.Distance(transform.position, nearEnd.position);
        RaycastHit hitInfo;

        if (Physics.Raycast(transform.position, (nearEnd.position - transform.position).normalized, out hitInfo, distance, targetObjLayer) && hitInfo.transform.CompareTag("Player"))
        {
            Debug.Log("Nope");
            while (finalPath.Count > 0)
            {
                finalPath.Pop();
            }
            Debug.DrawRay(transform.position, (nearEnd.position - transform.position).normalized, Color.red, 3f);
        }
        else
        {
            Debug.Log("entered");
            UpdatePathStartNTarget(nearStart, nearEnd, ref start, ref target);
            if (previousTIndex != target.myIndex)
            {
                previousTIndex = target.myIndex;
                Debug.Log(start + " , " + target);
                finalPath = AStar.AStarPath(RepresentGraphIn2DArray_AStar.instance.grapRepresentation, RepresentGraphIn2DArray_AStar.instance.allNodes, start, target);

                noedI   = RepresentGraphIn2DArray_AStar.instance.allNodes[finalPath.Peek()].transform.position;
                noedI.y = transform.position.y;
                Debug.Log(finalPath.Peek());
                finalPath.Pop();
            }
        }

        yield return(new WaitForSeconds(gapBtwPathChecks));

        StartCoroutine(FindPathAfter());
    }
Esempio n. 2
0
    private bool FindClosestFoodSource()
    {
        //Tile closestFood = lm.GetClosestTileOfType(ElementType.Lettuce, enemy.getCurTile().transform.position);

        Tile closestFood = enemy.goal;

        if (closestFood == null)
        {
            Debug.Log("NO FOOD TILE PRESENT ON MAP");
            return(false);
        }


        Debug.Log("current: " + enemy.getCurTile().id);
        Debug.Log("-----");

        foreach (Tile t in enemy.getCurTile().neighbors)
        {
            Debug.Log(t.id);
        }
        Debug.Log("-----");

        Debug.Log("target: " + closestFood.id);
        Debug.Log("-----");

        foreach (Tile t in closestFood.neighbors)
        {
            Debug.Log(t.id);
        }
        Debug.Log("-----");

        path = star.AStarPath(enemy.getCurTile(), closestFood);

        // a path to food is found!!
        if (path != null)
        {
            path.Reverse();
            this.foodTile = closestFood;
            Debug.Log("PATH FOUND");

            Debug.Log(" --- Length of path: " + path.Count);
            Debug.Log("Tiles ID's of path: ");
            foreach (Node node in path)
            {
                Debug.Log("id: " + node.tile.id);
            }

            Debug.Log("-----------");
        }
        else
        {
            Debug.Log("NO FOOD FOUND");
            return(false);
        }

        return(true);
    }
Esempio n. 3
0
    private void calculatePath()
    {
        start = enemy.getCurTile();
        path = star.AStarPath(start, end);
        path.Reverse();
        currentNode = 0;

        //target = path[0].tile.transform.position;
        //target.y = target.y + 1;
    }
Esempio n. 4
0
    // Calculate path to next waypoint
    private void calculatePath()
    {
        if (waypointIndex == enemy.waypoints.Count)
        {
            waypointIndex = 0;
        }

        start = enemy.getCurTile();
        end   = enemy.waypoints[waypointIndex];

        path = star.AStarPath(start, end);
        Debug.Log("Start is: " + start.name + ", end is = " + end.name);
        path.Reverse();
        currentNode = 0;
    }
Esempio n. 5
0
 private void FindPathToInitialPos()
 {
     path = star.AStarPath(enemy.getCurTile(), enemy.getSpawnTile());
     path.Reverse();
     currentNode = 0;
 }
Esempio n. 6
0
 public void StartFindPath(Node start, Node end)
 {
     Astarpath.AStarPath(start, end);
     ShowPath(end);
 }
Esempio n. 7
0
 public void FindClosestWaterPath()
 {
     path = star.AStarPath(enemy.getCurTile(), LevelManager.instance.GetClosestTileOfType(ElementType.Water, enemy.getCurTile().transform.position));
     path.Reverse();
     currentNode = 0;
 }