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.