Pathfinder flee going through structures

  • I have the following code

        //If there is literally no more construction targets, Hide somewhere away from everything
        if (!target) {
            var path =, => {return{pos:s.pos, range:5}}) , {flee:true, ignoreRoads: false} ).path
   // My own function to visualize the path

    I get the following result


    Am I doing something wrong? Why is it pathing through solid structures?

  • Hmm it looks ok to me at a glance, I can't see why it's not working!

    Two things I noticed:

    • ignoreRoads doesn't do anything

    • you seem to be recalculating that path each tick, which will have a cost

  • This could be a bug in the Pathfinder, where it counts all targets as walkable.
    Since you use every structure as a Target the Pathfinder treats them as walkable.

    But this is just a hunch and needs further investigation @o4kapuk

  • Also a temporary fix would be to provide a custom cost matrix with 255 for every structure.
    May help not sure.

  • @mrfaul Thanks for the suggestion. Seems to work in simulation.

    Further reading of the documentation at Pathfinder.CostMatrix does state that pathfinder only considers terrain data when finding a path. That should be further emphasized in Pathfinder docs. Reading of the sample code given at the side does show it generating a cost matrix and marking all structures as 0xff.

    Proposed solution:
    Introduce flee to creep.moveTo OR
    make all structures untraversable in the default costmatrix OR
    just make the documentation clear on that part.

  • It is not as simple as that, by default the Pathfinder does recognize static obstacles.
    Since in the usual case the Pathfinder should treat your goal always as walkable.

    You pretty much found a edge case by using flee where you define all structures as goals.
    So they are treated as walkable, this is more a unintentional side effect rather than a bug.

    So yes you have a very creative way of "abusing" the Pathfinder albeit a CPU heavy one.

  • @mrfaul said in Pathfinder flee going through structures:

    Since in the usual case the Pathfinder should treat your goal always as walkable

    Actually, that is not true for If you try to run it w/o any modified costmatrixes into a, say, source, you'll likely get an incomplete path, and nuke your ops.

  • Yes sorry, wrong choice of words was late.
    I oversimplified, I meant that like "as valid navigation node" so the Pathfinder assumes that it is walkable. And tries to reach it. This is still true in the flee case, since it recognized those as "valid nodes".
    Basically there is no check in place that kills the node if it isn't walkable.

    That is still true for the custom cost matrix, but due to the high values the Pathfinder will avoid those like a vampire the sun.
    I hope this clarifies what I meant.