Pathfinding to adjacent positions
-
In simulation mode, I have placed a source right next to my spawn in any non-diagonal direction. The path found has two steps instead of one.
var spawn = Game.spawns.Spawn1; var source = spawn.pos.findClosest(FIND_SOURCES); var path = spawn.pos.findPathTo(source); console.log(path.length) // Output: 2
By placing sources in all 4 non-diagonal adjacent positions, the path will have 3 steps!
-
I'd assume it's due to you trying to pathfind from one closed node to another closed node. Vanilla pathfinder will probably forgive this and try to offer an approximate path;
Why would you pathfind from one pos away antway? If you want this done in regular basis, just write a wrapper to findPathTo and return a direction with coords if the target is near to source;
-
I'm checking if there is exactly 1 space (a path of 2 steps) between 2 locations. But I keep getting results where the positions are adjacent. This never used to happen and doesn't happen for all adjacent pathfinding, only some particular situations. I could use some kind of workaround but it would be a lot easier if the pathfinding results were reliable.