Unexpected behaviour with pathfinding

0 favourites
  • 4 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • Hi all, it's been a long time (I was GeometriX on a previous account)!

    I've experienced what I can only describe as unexpected behaviour with pathfinding, specifically path costs.

    I have a little truck that uses the pathfinding behaviour, and I have roads as sprites that I want the truck to travel along preferentially, as opposed to blank space. My thinking was to set the road's path cost to something less than 10, as that is the default cost for objects (or 14). However, no matter what I set the road's cost to, even a negative number, simply setting it as a cost at all means that the truck avoids the roads as much as possible.

    I've tested this in numerous projects, including the template, and the behaviour is consistent. I would expect that any object with a cost set to less than 10 would be considered preferential over nothing (i.e.: no objects).

    Is this normal? Expected? Does anyone have any experience with this issue?


  • You should be setting the objects that are not roads to a high path cost, this means it will use roads primarily and opt to use blank space if it is a decent shortcut.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks plinkie, but this is the exact problem that I'm facing. It seems counter-intuitive to require non-roads as objects, as this means I need a high-cost "tile" (sprite, not tilemap) for each blank space. If I have road tiles, and higher-marked non-road tiles, then I need to fill my layout with non-roads, which seems like it should be an unnecessary thing to do.

    I get that this might be the workaround, but it feels like just that - a workaround, rather than an intuitive way to create a pathfinding system.

  • If you are using C2 runtime, I recommend trying EasyStarJS addon. (I don't know if it works with C3 runtime)


    It allows to set different cost for different tiles. So you can cover your whole layout with a tilemap, set tiles for roads and set cost=10 for all remaining tiles. EasyStar is much faster than the native Pathfinding plugin, has lots of features and you can use it in synchronous mode - update map and calculate path, all in one tick.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)