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?