AI / Path Finding Strategies in Box2D Games

I've recently implemented a very naive AI for enemies in the game I'm working on. Basically it consists of telling enemies to just move / jump / climb towards wherever the player is, and has the expected limitations - enemies don't know how to get around walls, etc. I'm pretty happy with it but keep thinking I can do something better. Have any of you implemented or have ideas regarding smarter AI solutions, path finding, or other tricks to make your actors "smart?"

One idea I had was to flood the open space with sensors that are linked to each other in a graph. If an enemy is in the same sensor-node as the player, it'll use the naive AI to move towards him. If not, then it'll find the shortest path through the graph and then use the naive AI to move towards the next node.

This is a totally new area to me, but pretty fun to think about.
That might be a good idea.

You could also consider giving the actors more complicated behavior, and less knowledge. (A complete node graph of the entire world is more knowledge than the player has 🙂)

You could perform raycasts to determine line of sight, and make the actors jump/walk accordingly. As long as they are following a certain 'behavior' they won't need to do more raycasts or 'think'. They might occasionally remember a point where they have already been, so they won't go to the same place twice, if the player wasn't there.
Yeah, I would try to do something like you've outlined and see if you can make it work before looking for a real solution - pathfinding in continuous worlds with physical constraints is a big field, and from what I remember even the simplest "serious" methods are pretty involved.

A lot of this stuff is done in robotics, if you're interested in learning more about it you can probably Google around a bit and find some unintelligible papers on the subject. 🙂
In robotics, robots usually build a 2d bitmap of their environment (using laser range finders, pretty much like a raycast). Then the space is (further) discretized, either by overlaying a grid on it, or by trying to find 'nice' points to put nodes in a node graph. From then it's just A* through the grid squares or the nodes.

Sometimes a "dilation" is performed on the shape of the walls in the traversability bitmap. This will have the effect that all the objects will become larger, but also that narrow paths will be closed if they are too small for the robot to get through.
If your game is tile based then use something like A* is ideal. There are some very good articles and code to be found.
Just a note, but A* is idea even if your game isn't tile-based - as long as movement can be modeled as a graph with known costs for each move.

Incidentally, I first learned A* from this page, and I highly recommend it:
http://theory.stanford.edu/~amitp/GameProgramming/
I think the idea of using static sensors would be a great way to keep track of where everything is in the world.

If you're grammatically generating your landscape, you can fill the 'air' with broken up static sensors and then use collision adds and removes to keep build your map. When the player and the monster share the same cell you can do the simple tracking, and more complicated tracking to get the mobs to the same cell.
dinedal wrote:
I think the idea of using static sensors would be a great way to keep track of where everything is in the world.

If you're grammatically generating your landscape, you can fill the 'air' with broken up static sensors and then use collision adds and removes to keep build your map. When the player and the monster share the same cell you can do the simple tracking, and more complicated tracking to get the mobs to the same cell.


Why would you need sensors for that? You have access to each body's position.
android wrote:
dinedal wrote:
I think the idea of using static sensors would be a great way to keep track of where everything is in the world.

If you're grammatically generating your landscape, you can fill the 'air' with broken up static sensors and then use collision adds and removes to keep build your map. When the player and the monster share the same cell you can do the simple tracking, and more complicated tracking to get the mobs to the same cell.


Why would you need sensors for that? You have access to each body's position.


To automatically update a path finding grid without polling.

Original thread: https://box2d.org/forum/viewtopic.php?t=3085