Conceptual help with influence map AI

I’m making an isometric grid based combat game, and could use help with enemy logic/AI. This is my first attempt at any sort of ‘intelligent’ enemy in a game. I’ve made my own isometric map, and enemies and player characters can make use of line of sight.

I’ve started with an influence map, giving each ‘gridcell’ instance two values, an enemy influence and a player influence. Before a character moves, they remove their influence from the grid, then put it back once they move. The closer a cell is to them, the higher influence value gets added to it. So higher enemy influence means enemies have control of that area etc.

I’m just trying to make a very basic behavior to start with, a ‘zombie’ that just goes towards the closest enemy: (for each reachable cell, target cell = cell with highest player influence). Reachable cells are determined by grabbing all cells within the character’s movement distance, then filtering those by which cells can still be reached taking pathfinding into account.

The issue I’m facing is once a zombie finds itself on the opposite side of a long wall from a player character, it will not recognize the cells on the other side of the wall as reachable, as they can’t be reached that turn by pathfinding. So basically it will just move a space or two then end its turn. Shuffling around on the opposite side of the wall for an infinite amount of turns.

My idea was to have influence “curl” around walls in a similar way to reachable cells, but running pathfinding on every cell of a 50x50 grid every time a character moves would make the game unplayably slow.

My next idea would be something like (for each cell within my initial movement distance, if one of those has higher player influence than my reachable cells, set that as my target cell). Then I guess they’d have to save that and pathfind to it. This would require me to track a ‘distance traveled’ and snap them to the nearest empty cell once they’ve moved their allotted amount. Which just seems hacky and prone to breaking.

So before doing that I thought I’d ask if anyone has any better ideas.

Is an influence map a better solve for the problem than classics like A* ?

Probably not, but I think I’ll need it for more advanced behaviors, so I’m trying to get used to it/build it well using a simple behavior based around it to start. I think I need to research/implement A* eventually anyway, as currently my movement distance is just an arbitrary number and all cells with their center within that distance will be reachable. I’m currently using NavMeshPlus for pathfinding, while trying to let the map do the decision making of what cell should be pathfinded to.

After implementing A*, yes, I think an influence map seems better for my needs. At least a lot of the time.

A* is very slow on a 50x50 map when the target cell is far away. The AI have to think for like 3 seconds before moving if their target cell is far away. I think I am back to my idea of using the map when far, and pathfinding when close. Even though I think it’ll cause the AI to walk up to walls before deciding to go around them lol. Unless I can find a way to optimize A* quite a bit.

Either way I can now use A* for pathfinding when I do need it, even if not use it to replace the influence map.

1 Like