- Home /
Too subjective and argumentative
Pathfinding to unknown location
Is it possible to have a different goal than to reach certain point? For example, reach any point that matches some given criteria? For example, I might want my agent to find the nearest and most suitable resource point, nearest water etc
Answer by Zodiarc · Feb 15, 2018 at 03:10 PM
You could hold a list of positions to each of the desired objects. Then if you command your agent to find for example the nearest resource point, you sort the resorce point array by distance to your agent and pick the first element.
Well, there are no desired objects. $$anonymous$$aybe I just want to find a most favorable spot. When A* traverses the cells, it scores each cell. Usually that's based on the distance to the target, but this could be anything. The goal is usually to reach certain point, but again this could be anything. I want to avoid implementing my own finding algorithm, because I'd have to bake my own data, implement my own dynamic obstacles, etc..
A* does need a starting and an ending point. Of course you could let it calculate paths to all objects on the map and pick the shortest one, but this wouldn't be very fast. I made an implementation of A* which adjusts dynamically to terrain and obstacles (obstacles can be also added on runtime, but since the grid is pre-generated removing them will cause weird effects).
Well, the point of A* is basically floodfilling the grid, scoring each cell and optionally using some heuristics to guess how prioritize the floodfill. But the endpoint is just one option how to end the process. You could simply search for any cell that matches your criteria.
Some pathfinding solutions implement a "cost" for each node, allowing for different terrain modifier etc. Astar Pathfinding Project is one example.