Esempio n. 1
0
    public void RequestPath()
    {
        Node startNode = grid.NodeFromWorldPoint(grid.mapData.start);
        Node endNode   = grid.NodeFromWorldPoint(grid.mapData.end);

        astar.AStarSearch(startNode, endNode);
    }
Esempio n. 2
0
    public void RequestPath()
    {
        Node startNode = grid.grid [Convert.ToInt32(grid.mapData.start.x), Convert.ToInt32(grid.mapData.start.y)];
        Node endNode   = grid.grid [Convert.ToInt32(grid.mapData.end.x), Convert.ToInt32(grid.mapData.end.y)];

        // Förstår inte varför startPos ligger i mapData.end och
        // endPos ligger i mapData.start ....... något fel vid inläsningen i MapLoader
        print("start: " + startNode.gridPosX + ", " + startNode.gridPosY);
        print(startNode.worldPosition);
        print("end: " + endNode.gridPosX + ", " + endNode.gridPosY);
        print(endNode.worldPosition);

        path = astar.AStarSearch(endNode, startNode);
        //	path = astar.BFS (startNode, endNode);
        print("Time since Startup:" + Time.realtimeSinceStartup);
    }
Esempio n. 3
0
    /*
     *  Function: HasPath
     *  Generates a path from the agent to the target via an A* search on the target
     *
     *  Returns:
     *      true if there is a path; false if there is no path
     */
    private bool HasPath()
    {
        if (path.Count > 0 && path[path.Count - 1].Contains(target.position))
        {
            return(true);
        }

        //generate new path to target
        //get the desired octree in scene
        GameObject[] octreeGOs = GameObject.FindGameObjectsWithTag("Octree");
        foreach (GameObject tree in octreeGOs)
        {
            if (tree.name.Equals(octreeName))
            {
                octree = tree.GetComponent <OctreeSetup>().octree;
                break;
            }
        }

        if (octree == null)
        {
            Debug.LogError("Octree does not exist");
            return(false);
        }

        //get start and goal nodes
        OTNode goalNode  = octree.TransformToNode(target.position);
        OTNode startNode = octree.TransformToNode(Agent.transform.position);

        astar.SetStart(startNode);
        astar.SetGoal(goalNode);

        //see if there is a path between start and goal
        if (astar.AStarSearch())
        {
            path = astar.GetPath();
            Debug.Log("Path has been generated!");
            Debug.Log("Path length: " + path.Count);
            return(true);
        }

        Debug.Log("NO PATH GENERATED!!!");
        path.Clear();
        return(false);
    }
 private Node GetSolvedNode()
 {
     return(aStar.AStarSearch(Board));
 }