#Tilemap navigation layers issues

1 messages · Page 1 of 1 (latest)

gentle brook
#

Using 4.2 stable:

I'm trying to create a tilemap with a few layers; One for the ground, one for walls, and one for objects so far.

I've made the ground layer navigable for my NavigationAgent2D and that's working fine.
The issue is that when I place an object on the Objects layer (which is above the ground layer) the agent is trying to walk through the object and gets stuck because of physics.

I believe this is because there is ground below the object and so the agent sees it as a valid path.

So is there a way to block navigation without deleting the ground tiles under my objects?

If the issue isn't clear let me know and I'll try to go more into detail

shell fiber
#

The TileMap Layers feature does not really work for navigation, at least not like users would expect when coming from rendering or physics.

#

the core issue is that navigation meshes can not overlap, so if you want to "stack" navigation mesh polygons in 2D you can only do so by placing them on different navigation maps.

#

This is why the TileMap only places the TileMap Layer0 navigation polygons on the default navigation map. Any TileMap Layer > 0 creates a new navigation map and places all navigation polygons from that layer on that map. You can get the navigation map RID for a layer with the TileMap get navigation map functions. That map RID is used in all the NavigationServer2D API functions that requires a map RID.

#

With that RID you can change the navigation map that NavigationAgents should use with the set_navigation_map() function on the agents. So you can switch the agents between "ground" and "wall" or whatever state they are.

#

the navigation_layers bitmask that you see often are "polygon filters", they filter what navigation region polygons the path query can use, they do not affect what and how things are placed and merged on the navigation map.

gentle brook
# shell fiber The TileMap Layers feature does not really work for navigation, at least not lik...

Bummer, so would I need to use a different solution to do what I'm trying to do? Like a NavigationRegion2D?
I'm pretty new to Godot and the nav stuff so I didn't fully understand everything you said, sorry! 😅
I'm basically just trying to figure out a good solution for making an area with objects and navigating an agent around, but I want the player to be able to place objects down (like decorating) and the agent to navigate around that stuff.

#

I was messing around with NavigationRegion2D and that seems to work pretty well but I kinda wanted to use the tilemap because it's so handy for painting all the terrain.

shell fiber
#

you can use the TileMap to build your level, add tilemap cells with navigation polygons or collision polygons on TileMap Layer0, then bake the result with a NavigationRegion2D parent.

#

if you dont want the TileMap as a direct child of the NavigationRegion2D you can give the TileMap a node group name and add this group name to the NavigationRegion2D NavigationPolygon source group name and switch the navigation mesh baking source geometry mode to use groups.

#

also if you use the NavigationRegion2D you need to disable the "Navigation enabled" property of your TileMap Layer, else the tilemap will create navigation regions that will conflict with the navmesh of the NavigationRegion2D.

gentle brook
#

Ok so I have the ground tile with a nav poly, and the wall tiles with no nav poly but instead a physics poly. I disabled Navigation Enabled on all 3 of my tilemap layers, and I only have 1 Navigation Layer (Navigation Layer 0).

I also made the TileMap a child of NavigationRegion2D.

I made a polygon on the NavigationRegion2D that completely encases the TileMap and after pressing Bake it's still adding navigation under objects that I want to block Navigation with (from the other TileMap layers).

#

Sorry if I'm just not understanding something

shell fiber
#

if you only use the TIleMap you do not need to draw and outline with the NavigationRegion2D

#

in fact drawing an outline around the TileMap might cause polygons to flip in the wrong direction

#

the NavigationRegion2D will only parse the TileMap Layer0, it ignores all other layers

gentle brook
#

Oh, I was drawing the outlining polygon because of the warning: "A NavigationMesh resource must be set or created for this node to work. Please set a property or draw a polygon"

#

I couldn't figure out a way to set the TileMap as the "property" so I drew the polygon

shell fiber
#

That outline drawing is required for everything, except for TileMap, TileMap is a special case because it has traversable navmesh polygons as internals

gentle brook
#

Hmm, in that case I must be doing something wrong because I get no navigation when I just have the TileMap as a child to the NavigationRegion2D.

Is there a setting I have to set to change from polygon to TileMap on the NavRegion?

gentle brook
#

Oh I see, I think I need to add the NavigationPolygon in but just not create any points for it

#

So yeah it does look like that's generating a proper nav mesh (though it seems to work just like using the TileMap's "Navigation Enabled" feature)

#

What would be the best solution to being able to make multiple tilemap layers like so:

#

But being able to consider the objects with colliders/navigation on those layers into my final nav mesh?

#

Maybe my first layer, instead of being a ground layer, could be a layer that places tiles for navigation after checking what tiles the other layers have?

#

It could place a nav tile on all ground tiles in the ground layer, but then if there is an object on that same location in the object layer, delete that ground tile for example

#

then just make them invisible

#

Not sure if there's a cleaner way of doing that

gentle brook
#

So I ended up solving this by just having multiple Tilemaps. It made for a pretty easy solution.

#

I made a dedicated Tilemap for each part that needed it's own category and should block navigation, and I'm only using tilemap layers for aesthetic things that don't actually affect the navigation polygon (like rugs on flooring)

north zinc
hollow coral
#

what I use as a solution is I just bake a new navigation polygon on a separate region using code, in the code I can check tiles to see what actual spaces are valid for navigation and it also allows me to add a agent radius so they dont get stuck on corners

#

this has the added benefit of just using whatever layer I want specified by the regions I am applying this new polygon to

north zinc
#

is it possible to bake multiple tilemaps into one navmesh?

hollow coral
#

well sure, its just a matter of looping through all tiles you want to be part of the mesh, I am essentially just adding outlines in the shape of the navigation shape of the tile at that tile's position

north zinc
hollow coral
#

oh, iirc you cant

#

or maybe its separated by the navigation layers in the tilset

north zinc
#

i tested it and you can actually (multiple tilemaps, not tilesets)

#

so i just make a new tilemap for each layer with collision and then bake them into the navmesh