Incorporate occupied nodes into path calculation

I’m using node tags to prevent players and enemies from occupying the same nodes. I have also written an OccupyManager that keeps track of which units are currently occupying a specific node using a dictionary, with the node index being the key.

My problem is that two enemies should not be able to occupy the same node, but still need to tag their nodes as “enemy” nodes for the other agent’s sake.

If I could incoporate my own system either on top of this or in place of, that would be ideal, but I am at a loss as to where to start.

When a path is being calculated I would like to incorporate the following lines:

GameObject requestingEnemyUnit; <---the unit requesting the path
////
if(OccupyManager.instance.CheckForNode(node)) //see if the current node being checked is occupied
{
    OccupiedNode occupiedNode = OccupyManager.instance.GetOccupiedNode(node); //get the OccupiedNode object that contains info on a specific nodes occupiers
    foreach(GameObject unit in occupiedNode.occupiers) //go through the node's occupier list to see if there is an enemy unit occupying that node, that is NOT the enemy unit requesting this path
    {
          if(unit != requestingEnemyUnit)
           {
                   //consider this path unwalkable
           }else
           {
                  //the unit must be this unit, therefore we're good
           }

    }
}

Any suggestions? I would greatly appreciate any help.

Hi

You might find some interesting tips here: https://arongranberg.com/astar/docs/turnbased.html, also check out the ‘turnbased’ example scene.

Just wanted to reply and say that the TraversalProvider worked great with the system I had already built. What I ended up doing was overwriting the CanTraverse method. I had to provide the GameObject for comparision to other occupiers, so that meant that I couldn’t use multithreading unfortunately. The good news is that this asset is so well optimized that I’m still getting over 80 fps using over 75 agents.

Thanks for the advice!

1 Like