I have a manager script that generates a FloodPath. Multiple Seekers will request the path (FloodPathTracer) when they spawn and head towards the target. This code works properly.
How I generate the FloodPath:
_floodPath = FloodPath.Construct(destination.transform.position, null);
AstarPath.StartPath(_floodPath);
_floodPath.BlockUntilCalculated();
How I generate the FloodPathTracer:
FloodPathTracer fpathTrace = FloodPathTracer.Construct(startPosition, _floodPath, null);
This all works properly. But what I want to do is have the Seekers randomly choose a fork in the path. There’s a spot where the path goes around a space to the left and the right. I want the Seekers to randomly pick one of those. The image below shows what I am trying to do. The Seeker follows the red arrow from the left and then needs to go left or right (to the orange or red tile).
How I was implementing it was through tags and tagPenalties. The tags are set properly (I can see the colors in the inspector) and I think I am setting the tagPenalties correctly, but they seem to be getting ignored.
I have tried applying tagPenalties to the FloodPathTracer and the Seeker (and both) and the Seekers all take the same route, which is the one they took before attempting to add this “forking” concept.
Testing with a randomly generated penalty (at the FloodPathTracer level):
int[] tagPenalties = new int[32];
switch (randomPathIndex)
{
case 0:
tagPenalties[2] = 20000000;
break;
case 1:
tagPenalties[1] = 20000000;
break;
}
fpathTrace.tagPenalties = tagPenalties;
And testing at the Seeker level:
int randomPathIndex = UnityEngine.Random.Range(0, 2);
int[] tagPenalties = new int[32];
switch (randomPathIndex)
{
case 0:
tagPenalties[2] = 20000000;
break;
case 1:
tagPenalties[1] = 20000000;
break;
}
seeker.tagPenalties = tagPenalties;
path = AIPathManager.instance.GetPathToBase(gameObject.transform.position);
path.nnConstraint.graphMask = seeker.graphMask;
path.tagPenalties = seeker.tagPenalties;
path.enabledTags = seeker.traversableTags;
seeker.StartPath(path, OnPathComplete);
Again, nothing I do seems to affect the paths. Any ideas of what I am doing wrong here?