Very stupid pathfinding Godot 4.2.1

Godot Version



I have a procedurally generated map that has resources with colliders (land does not have colliders). After generating resources on the scene, I bake a navigation polygon and I have, I don’t know how to say, “artifacts”, many very small polygons (there are also large ones). And when the navigation agent tries to pass through them, it creates incomprehensible paths.
Path example

1 Like

have you tried using navigation layer built-in in tilesets?
Using this, you will not need to use NavigationRegion2D and the mesh thingy to make the walkable navigation path

Tilesets are not suitable for me because I have a lot of interactions set up with resources, for example, each tree has 100 HP, but on the tile map I got 100 HP for all trees (If I clicked on 1 tree and took away 20 HP, all the trees got 80 HP).

I tried using custom data layer, but it didn’t work. How to assign data to a separate cell? It turned out that one data was assigned to the entire map…

So, I watched a lot of videos about navigation and almost all of them were shown on a tile map. I tried to transfer all this but was limited by the fact that I cannot interact with objects

custom data layer is basically what the tilesets’ specific tile’s custom data, it will be the same custom data for all of the same tile

as for modifying specific tile’s value during runtime, it can be done with 2 tilemap’s built in methods like shown here

you can spawn the tree as an object to be interact with, but the navigation path will also be produced by tilemap’s tilesets’ navigation layer’s tile

if the tree can be moved, then it will be a lot difficult to do the above method, but doesnt look like the tree/rock can be moved, so you can let the tilemap’s tilesets’ tile’s navigation layer to have the navigation

this is what i meant by the “tilemap’s tilesets’ tile’s navigation layer”

1 Like

Thanks, I was able to change the hover color and track the click.
But I don’t understand, the custom data layer works as a static class, and the TileData class has only a few standard properties.
How can I add variables with data to each tile so that I can access and change the data of that particular tile?

you can spawn the tree as an object to be interact with, but the navigation path will also be produced by tilemap’s tilesets’ navigation layer’s tile

do you mean that I should draw them on the tile map and just initialize the object on the scene at the same coordinates?

yes, so it can be interacted easily with its own script
as for draw, it could be just a tile with inside of the tree is not part of the navigation, so it wont be calculated, so you draw the tile but when it’s the spot for the tree to spawn at, it uses this modified tile with the inside of the tree size is set so that it wont be tracked by navigation agent to be “walkable” inside the tree

1 Like

Such broken paths are the result of wrongly merged navigation mesh edges.

They are typically caused by having navigation meshes that overlap each other. E.g. having the NavigationRegion2d navigation mesh and the TileMap build-in navigation enabled at the same time or having more than one TileMapLayer that places a navigation mesh polygon over the same cell. It is also caused when edges are squeezed so that they all end up in the same or wrong rasterization cell of the navigation map.

In general a “perfect” grid alignment of polygon objects will cause random troubles with polygons across the engine. A lot of geometry functions will fail at random positions due to how most geometry function calculate in 2D what is inside / outside an outline. This is noticeable when moving e.g. a tree just by 0.05 (or some other small epsilon) and suddenly the majority of polygon issues disappear.

1 Like

I was able to solve the problem without tilemap navigation.

The problem with artifacts went away on its own, but the problem was not that, problem was in the property of the navigation agent - path postprocessin (It has been setted edgecentered).

As far as I understand, such strange navigation paths on the custom navigation polygon are caused by the algorithm that is used. When moving from polygon to polygon, the agent looks for a common line of contact, calculates the median point and passes through it. This is especially noticeable if you are using tile map navigation. And due to my polygons are curved, path turned out to be complicated
I can’t insert 2 pictures, I’ll add one more reply

Thank you for your help friends!

1 Like

It’s all due to poor English and inattention

Resources are also created procedurally, but are shifted to the edge of the cell. As you can see from the debug mod, their colliders are not taken into account in navigation. And the search for a path goes through the middle lines

NavigationAgent edge-centered path postprocessing forces each path point in the middle of any crossed-edge along the path. It has limited use outside of projects that use fixed layouts like square tile or hex games due to all the path detours it creates when the edges are not same sized everywhere.

Physics colliders are never directly taken into account by the navigation system as they are part of a different engine system, the physics engine. What the 2D navigation mesh baking does is that it parses the physics shapes to convert it into data that the navigation system actually uses, in this case the navigation mesh surfaces. That is why every change of a physics shape requires a new bake, by default a physics engine change does nothing for the navigation system.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.