A* Pathfinding Project

Targeting Player vs. Barriers/Obstacles


#1

I’m in the midst of writing a zombie AI and recently switched from Unity’s “lovely” NavMeshAgent system to A* (loving it so far by the way)

However I’m trying to work out how to do something. Players are targetable entities, and they are surrounded by barriers on all sides (it’s a wave shooter). I can make those barriers targetable too, but…

What I’d like to do is make it so that the enemies will try to go for the players, but if it’s impossible (i.e. no barriers are broken) they’ll target the barriers instead. But if there is a barrier open I don’t want all the zombies to funnel in one side of the player area, they should opt to attack the barriers nearer them instead as it’s a lower cost to them compared to walking all the way around a square of barriers to find the one hole in the barrier wall.

Where would I start on this? I’ve got zombies targeting players, and I can set it so that if they can’t path to players (using IsPathPossible) they attack the nearest available barrier, but that doesn’t solve the funnelling issue if there is an open barrier.

I’m wondering if perhaps I should calculate paths to all barriers and their chosen player target, and see if the cheapest barrier path is x amount cheaper than the path to the player and opt for that instead. Or maybe there’s a better way?


#2

Hi there, I’m new on this asset too.
Just wanted to mention, this multi target path feature seems what you’re looking for

https://arongranberg.com/astar/docs/old/class_pathfinding_1_1_multi_target_path.php
https://arongranberg.com/astar/docs/multitargetpath.html

The default behavior is choosing the closest one but maybe there’s some method to modify the weight of each target depending on the factors you mentioned. Maybe someone could help with that :smiley:

Cheers!


#3

I think that’s pretty much what I came up with, though instead of calculating the path cost up front I calculate it based on distance after the fact (and calculate all paths)


#4

Hi

Another option is to use tags.
You can mark all of your barriers with a specific node tag (see https://arongranberg.com/astar/docs/tags.php) and then on your Seeker components make that tag have a very high cost. This will make the agents able to “walk through” barriers, but they will avoid it most of the time if there is a shorter route.

You should make sure to stop your agents from actually walking through the barriers though. Make them start attacking them instead.