How to make Agent movement choice smarter?

Hi there,

Currently I developing top down 2d zombie game, there is player character, NPC as partner/team and zombies.

I have a problem related to Agent / NPC movement choice

The player and partner (NPC) is being chased by horde of zombies

Zombie agents is targeting both player and NPC, choose the closest position.

The problem is, the NPC (blue marked) movement choice is bad, it should move to the orange line since there is no obstacles and can avoid zombies.

How to solve this issue?

Hi

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.

Thanks for your reply,

I just try your recommendation to use RaycastModifier but it not work as what I want.

fdfdgfdg

What I want is to find a path to avoid enemy agents, not push at it.

Is this possible to be achieved with your plugin?

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.