Mail Archives: djgpp/2000/04/23/10:12:08
>I need information about AI, path finding algorithms.
Here's one pathfinding algorithm:
Let A be the object doing the pathfinding, and let B be the object you're
trying to find.
Do a floodfill, starting from B. This spreads in all directions, and will
eventually find A (assuming there is a path).
Create a separate array, shaped like the level, for these purposes. We'll
call this 'flood-fill space'.
Initialise the floodfill space to -1. When you start the floodfill, store 0
in the starting square. Each time you spread to the next square, increment
the number. Make sure you detect when the floodfill finds object A.
Then object A can follow the path of decreasing numbers.
If you have multiple B objects, you can do a floodfill from A first to
determine which one is nearest.
I refer to squares above, but this will work with any level units.
Hope this helps,
Ben Davis
- Raw text -