Creating Pathfinding Tables... how?

Started by
2 comments, last by Kylotan 16 years, 12 months ago
I am having a hard time visualising how pathfinding works. I have read several tutorials on the subject over and over, and although I understand the concept behind pathfinding, I am having a hard time putting it into something workable. Let's take a simple 2d screen size, of 800x600. Lets say I want to divide the screen into blocks of 10x10. So that would be a grid of 80x60. I know each block would have to somhow contain the weight it is to go from itself to the other 8 blocks that surrond it, and infinity for blocks that aren't passable. So the question is, how do I track all this? Do I manually write out 4,800 arrays, or tables, or what is the best way to create the tables. Lets say I get into adding walls and stuff, obviously I will set the tiles weight to infinity, but then how does the pathfinding system know that this tile is no longer the origonal weight, but the new weight? I won't even get into a 3d environment, where you can go from upstairs, inside and out of building, etc. Please help me understand. BUnzaga
Advertisement
If you have the cost to move into a given block, then you only have 4800 values to store. Then, read about A* to find the optimal path from one point to another. Google A STAR to find lots of info, or search this forum, where there are gobs of links and information.
Your screen has 800x600 = 480,000 pixels on it! Do you write out the color for every pixel? These pathfinding values are no different.
- "So the question is, how do I track all this? Do I manually write out 4,800 arrays, or tables, or what is the best way to create the tables."

Usually the cost of entering a square is the same regardless of which side you come from, so you only need 4800 values, not 4800x8 values.

- "Lets say I get into adding walls and stuff, obviously I will set the tiles weight to infinity, but then how does the pathfinding system know that this tile is no longer the origonal weight, but the new weight?"

A wall is something you add once. So you set the weight of that square to the appropriate value (infinity or whatever). It's just a value, no magic there, no need to remember old or new values.

- "I won't even get into a 3d environment, where you can go from upstairs, inside and out of building, etc."

It's no different in principle, just more adjacent squares for each one.

This topic is closed to new replies.

Advertisement