From a pathfinding perspective, both paths are equally good (same length). You can use the Raycast Modifier to simplify the path, which I would recommend. That will make it take a more direct path.
Local avoidance will then try to avoid the other agents using the minimal amount of effort.
I think I figure out how to fix it, I just fund “Tag Penalty”, something I want.
My script:
void UpdatePenaltyPosition()
{
// Used for enemy
if(!isEnemy) return;
// Update the pathfinding graph to reflect the enemy's move
GridGraph gg = AstarPath.active.data.gridGraph;
// Get the node at the last recorded enemy's position and remove the tag
GraphNode oldNode = gg.GetNearest(transform.position, NNConstraint.Default).node;
oldNode.Tag = 0; // Assuming 0 is the default tag
// Update the enemy's position
//transform.position = newPosition;
// Get the node at the current enemy's position and set the tag
GraphNode newNode = gg.GetNearest(transform.position, NNConstraint.Default).node;
uint enemyTag = 1; // Set this to the index of your tag
newNode.Tag = enemyTag;
}
For non-enemy, add this on start:
seeker.tagPenalties[1] = 1000;
Also I set “Tag” penalty value from seeker properties (Editor), Tag 1 value to 100 for non-enemy agents.