At 1/8/16 07:44 PM, MSGhero wrote:
The other other thing is do you really need the _optimal_ path? Like if 0,0 pathfinds to 399,399, you know that path will be invalid in like 5 seconds. Maybe scale the distance down to a max of X and pathfind to that tile before pathing to the next step until the goal.
This is actually not such a good solution. I think you would realize this quickly if you started to implement it.
First off how would you decide on a shorter path ? Do you just guess based on, say, the half way point ? There is no such thing as "scaling the distance down" with A*. You recursively search neighbors until you find the destination. You could stop after some number of iterations and choose the point with the best heuristic distance, but you may end up with a point very far away, or in the wrong direction entirely of your destination depending on the layout of the map.
Another problem, what if our final destination is in fact not reachable at all ? How would we figure that out before we started moving the unit toward the shorter point in the first place? Well, we could try to pathfind to the final destination, but doesn't that then defeat the whole purpose of the scaled distance solution, as we already have the final path ?
It's not all about movement either. What if the unit needs to decide which nearby enemy to attack. He needs to figure out which of them are reachable from his position. Maybe some are in an enclosed structure, or blocked by other units. How do you use your scaled-down solution to solve this problem ?
Also as I mentioned before, dijkstra maps don't work well when the destinations are constantly changing. The article you linked seems like a bad solution for this reason.
I think it's probably going to be difficult to solve the problem remotely without knowing all of the requirements, and seeing the actual implementation. I do appreciate the suggestions, though. :)