What's the best method to send multiple pathfinding directions?
Posted: Tue Jun 14, 2016 7:33 pm
Hi everybody!
I'm currently working on an 2.5D isometric game which will have dynamic pathfinding and terrain creation (the user manually creates the terrain, the coordinates are logged, and the pathfinding adapts to the changes). The pathfinding will give directions to little people-like entities when they want to reach a specific tile.
(example of potential terrain)
My current grid system works by using this code to create a coordinate grid within a table in the format "grid[xTile][yTile]": (also contains additional info to get the actual coordinates for x and y in the world).
A visual example after drawing everything is as follows:
After this table is created, a new table (terrain) is created which logs the x and y grid position (plus a few things like image name) of any tiles that have been placed into the world. This allows me to iterate through that table and find any matching grid coordinates when selecting a location for my pathfinding.
Currently, I'm subtracting the desired finish point from the starting point, check if the number is negative or positive, then iterate up or down through the table terrain (based upon if the number was positive/negative) looking for potential tiles available leading toward the desired point.
However, the roadblock I'm currently at is that I have no idea how I should give the info to the people-like entities mentioned earlier. A table seems like the best way to store the info, but if I'm giving directions to multiple entities at once it'll likely overwrite the directions for the first.
So, to summarize the question -- what would be the best way to save and send multiple lists of directions to each entity?
Thank you to anybody who attempts to help by giving advice or steering me in the right direction.
http://pastebin.com/R0873aQv (pastebin to the current main.lua)
(Attached will also be the .love file)
I'm currently working on an 2.5D isometric game which will have dynamic pathfinding and terrain creation (the user manually creates the terrain, the coordinates are logged, and the pathfinding adapts to the changes). The pathfinding will give directions to little people-like entities when they want to reach a specific tile.
(example of potential terrain)
My current grid system works by using this code to create a coordinate grid within a table in the format "grid[xTile][yTile]": (also contains additional info to get the actual coordinates for x and y in the world).
Code: Select all
local function gridLoad()
if preload then
for x=1, gridSizeX do
grid[x] = {}
for y=1, gridSizeY do
grid[x][y] = { x = 0, y = 0}
if x == gridSizeX and y == gridSizeY then
preload = false
end
end
end
end
end
After this table is created, a new table (terrain) is created which logs the x and y grid position (plus a few things like image name) of any tiles that have been placed into the world. This allows me to iterate through that table and find any matching grid coordinates when selecting a location for my pathfinding.
Currently, I'm subtracting the desired finish point from the starting point, check if the number is negative or positive, then iterate up or down through the table terrain (based upon if the number was positive/negative) looking for potential tiles available leading toward the desired point.
However, the roadblock I'm currently at is that I have no idea how I should give the info to the people-like entities mentioned earlier. A table seems like the best way to store the info, but if I'm giving directions to multiple entities at once it'll likely overwrite the directions for the first.
So, to summarize the question -- what would be the best way to save and send multiple lists of directions to each entity?
Thank you to anybody who attempts to help by giving advice or steering me in the right direction.
http://pastebin.com/R0873aQv (pastebin to the current main.lua)
(Attached will also be the .love file)