Navigation2D: discourage travelling through certain zones

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bloozlump
:warning: Old Version Published before Godot 3 was released.

Sorry for this long question, I’ve tried to make it as quick as possible but I have to clarify a few things not to be misunderstood.

In brief: I’m trying to discourage (or encourage) the entities that use pathfind from travelling through certain zones, while still allowing to use them if other paths are blocked or too long.

Long version: I’m making a 2d isometric rogue-like game with randomly generated maps. The terrain will often be covered by a sticky substance (that i call “blob”) which halves the speed of any entity, and I want enemies to act as if they knew that. Since a longer route may actually be completed in a shorter time (i.e. by circumventing the blob), enemies should choose their path considering not only the distance travelled but also the slow-down effect.
If i were to code a pathfinder by myself, I would use a graph and place a node on every tile. The nodes with blob would have a different (bigger) “weight”, as if they were put farther away from the others: the algorithm would still choose the shortest path… but this way it would also take into consideration the slow-down.
Anyway Godot already has a nice pathfinding algorithm and I thought it would be better to use what I have rather than reinventing the wheel.
Just as a reference, this is my general level setup.

I need to keep separated the three tilemaps (the tiles have different dimensions and should be drawn in that order). According to this question, to add the pathfind I should

basically make a new scene and add sprites the way you normally make a tileset, then you can attach NavPolyInstances to each tile. Then in your map scene, make the TileMap a child of a Navigation2D and all the NavPolyInstances on the tiles will combine.

In my case, I should use the “blob” tilemap. But here’s my problem:
If I’m not mistaken, the Navpoly simply says “you can travel here” or “nope, not here”. I’m looking for something in between, like “you can travel here… but you shouldn’t”.
Do you think there’s a way to use the Navigation2D to make the entities act as I described, or is it better to create a new pathfinder from scratch using weighted nodes in a graph? (…or… something else, maybe?)

(On a side note: my problem is actually more complicated… There are actually two types of blob, A and B, and two types of enemies: “A” enemies are slowed by “B” blob and accelerated by “A” blob, and vice versa. So they should avoid the enemy blob and stick close to their own. Anyway I suppose I can manage on my own if you help me solve the one I described. )

I have an idea how to do that but it involves writing the pathfinder from scratch in order to see obstacles as a “difficulty” rather than “walkable/not walkable”. It would be to implement A* or Dijkstra with that in mind. If your world is a grid that should be straightforward, otherwise you would need to figure it out yourself from NavigationPolygons or waypoints.

Zylann | 2016-08-18 23:52

Too bad… I hoped to find an alternative, but it seems impossible with the standard navigation2d. I could reduce the interest of the entities for things that happen inside the blob, but they would still carelessly cross those zones. It seems that my only option is coding the pathfinder on my own. Oh well, thanks for your answer anyway!

Bloozlump | 2016-08-21 11:39