Original Post
I've been thinking about how I would setup the pathfinding nodes/edges for the heightmap based terrain in the RTS game I'm working on. The method I've come up with thus far is as follows: 1. Get all vertices and edges from the terrain mesh 2. Create a node at every vertex and pathing edge for every edge 3a. Loop through every edge, finding it's slope angle 3b. If angle > maxAngle, delete edge and mark edge's nodes (vertices) as red 4a. Loop through every edge 4b. If the edge's nodes (vertices) are both red then delete edge 4c. If the edge has 1 red node then mark the other node as blue 5. Loop through every edge and delete those that don't have 2 blue nodes 6. Loop through every node and delete all those that aren't blue (I called the nodes blue and red in this instance to correlate with the picture below) After that, assuming I'm not mistaken, there should be remaining only an edging around any rises or falls that exceed the slope limit. This picture should help show what I mean. The green edges are those that exceed the slope limit. The red nodes are those that are connected to edges that exceed the slope limit. The blue nodes are those that are connected to edges with one red node. The yellow edges are those that have 2 blue nodes.
The yellow edges and blue nodes are the ones that would be kept in the end. Given that I now have the boundaries, I could run through each remaining node and check it against every other node and see if there is a boundary (yellow edge) between them (on the x-z plane) and if not, create a new edge between them. I'm pretty sure that after that I'd have all I needed for pathfinding to anywhere. At run time when pathfinding from A to B I would: 1. Get closest node to A and pathfind to closest node to B 2. Check if there's any blockage between closest node and next node on path and if not, drop the closest node and go to the next node 3. At second last node on path, check if there's any blockage to B and if not, go straight to B I'm pretty sure that this will all work, but I don't want to start implementing it without being sure so my questions are: Is this going to work and/or is there a better way? Also, what would be the best way to incorporate dynamic blockages at runtime (eg. built buildings and other units)? I would think ignoring them when doing all the pathfinding and just using flocking to get around them. [Edited by - Matt Carr on May 18, 2008 12:14:44 AM]
The yellow edges and blue nodes are the ones that would be kept in the end. Given that I now have the boundaries, I could run through each remaining node and check it against every other node and see if there is a boundary (yellow edge) between them (on the x-z plane) and if not, create a new edge between them. I'm pretty sure that after that I'd have all I needed for pathfinding to anywhere. At run time when pathfinding from A to B I would: 1. Get closest node to A and pathfind to closest node to B 2. Check if there's any blockage between closest node and next node on path and if not, drop the closest node and go to the next node 3. At second last node on path, check if there's any blockage to B and if not, go straight to B I'm pretty sure that this will all work, but I don't want to start implementing it without being sure so my questions are: Is this going to work and/or is there a better way? Also, what would be the best way to incorporate dynamic blockages at runtime (eg. built buildings and other units)? I would think ignoring them when doing all the pathfinding and just using flocking to get around them. [Edited by - Matt Carr on May 18, 2008 12:14:44 AM]