A* Pathfinding Project

GraphUpdateUtilities.UpdateGraphsNoBlock Question


#1

Hello,
I’m currently trying to use the UpdateGraphsNoBlock function but am encountering difficulty.
For some reason the method is returning true for the area blocked off in the attached image
reachableNode

I want my game to think that touching corners is a blocked path, but it currently does not. My code is as follows:

  //pathfinder.FloodFill();
            Debug.Log(currentPlaceableObject.name);
            Debug.Log(newestTower.name);

            GraphUpdateObject tower = new GraphUpdateObject(currentPlaceableObject.GetComponent<Collider>().bounds);
            Boolean allPathsAreClear = GraphUpdateUtilities.UpdateGraphsNoBlock(tower, allPathNodes, false);
            //Boolean isPathPossible = PathUtilities.IsPathPossible(allPathNodes);

            Debug.Log("Paths are clear: " + allPathsAreClear);
            //Debug.Log("Is path Possible: " + isPathPossible);
            if (allPathsAreClear)
            {  //Then do stuff 
               }

Can anyone tell me how to set up A*pathfinding to calculate blocked paths in this way?
I appreciate any help you can provide.
Thanks


#2

Hi

How is your allPathNodes list defined?


#3

Hi Aron,
The allPathNodes list is defined and populated using the following code

// Root of the Mono behavior script
    private List<GameObject> checkpoints = new List<GameObject>();
    private int buildCount = 0;
    private List<GraphNode> allPathNodes = new List<GraphNode>();
// both lists are populated in Start method

    void Start()
    {
        pathfinder = GameObject.FindGameObjectWithTag("Pathfinder").GetComponent<AstarPath>();
        GC = GameObject.FindGameObjectWithTag("Controller").GetComponent<GameController>();
        nodeSize = pathfinder.data.gridGraph.nodeSize;
        offset = new Vector3(nodeSize * 0.5f, 0, nodeSize * 0.5f);
        AddCheckpoints();
        GetPathNodes();
    }

// The relevant functions are as follows
    private void AddCheckpoints()
    {
        checkpoints.Add(GameObject.FindGameObjectWithTag("Start"));
        checkpoints.Add(GameObject.FindGameObjectWithTag("End"));
        foreach (GameObject checkpoint in GameObject.FindGameObjectsWithTag("Checkpoint"))
        {
            checkpoints.Add(checkpoint);
        }

    }

    private void GetPathNodes()
    {
        foreach(Transform tf in allCheckpoints)
        {
            GraphNode thisNode = AstarData.active.GetNearest(tf.position).node;
            //GraphNode thisNode = pathfinder.GetNearest(tf.GetChild(0).position).node;
            allPathNodes.Add(thisNode);
        }
    }

#4

Hi

Can you verify that if you set the Graph Coloring mode to ‘Areas’ then the inside of that region should have a different color than the outside (right now when using the ‘Solid Color’ mode they are both blue).
Also can you verify that one of your checkpoints is inside that region?


#5

I have switched to regions, and can confirm a checkpoint is inside the perimeter of the wall of gems


This first screenshot the region inside the circle of gems is counted as unreachable and I cannot place a gem in the top right corner, however in this second screenshot that is not the case.

ReachableChecpoint
In this the region looks like a very slightly different color but It still calculated as reachable when I place a new gem and detect if its blocking the path. (Intended functionality is to destroy the gem, essentially preventing the placement.

Any ideas as to how to get around this problem?


#6

That is strange. I cannot see why it wouldn’t work in the second case as well. Do you think it would be possible for you to share a small test scene that I could use to replicate this issue?


#7

I’ll work on trying to put a sample scene together over the weekend. though I haven’t done that before.