#Does Navigation 2D support moving tilemaps/regions?

13 messages · Page 1 of 1 (latest)

muted island
#

I'm working on a game that has the player entering a vehicle. The vehicle and the levels are made out of tilemaps (top down perspective).
I would like NPCs to be able to enter the vehicle and path around it while it's moving. I've tried a couple of ways to get this going:

  1. Tilemap navigation for levels, NavigationRegion2D for vehicle.
    This seems to work while everything is stationary, but when the vehicle moves the path fails to update beyond the original bounds of the NavigationRegion2D. I suspect that it's not detecting the change somehow. I attempted to update the local position and to rebake the region, but neither worked.
  2. Tilemap navigation for levels and the vehicle
    I have performance problems with this - moving the vehicle tanks the frame rate, I think it's due to trying to connect the navigation polygons even though the vehicle uses a separate navigation layer. Also, lining up the navigation polygons seems quite difficult, the Npcs fail to cross from the level into the vehicle.

Anyone have any ideas or handled something like this before?
I'm using 4.2 RC1.

muted island
#

I think I got this working now. Looks like the NavigationRegion2D doesn't update the NavigationServer2D when the global position changes. I fixed it by doing it manually with the following code:

var nav = GetNodeOrNull<NavigationRegion2D>("%NavigationRegion2D");
var rid = nav.GetRegionRid();
NavigationServer2D.RegionSetTransform(rid, nav.GlobalTransform);
#

I guess this is an engine bug, because the docco says it should happen automatically 🤷

hardy geode
#

That said moving a navigation mesh every frame like that is super costly because the navigation maps need to update all the time in full

muted island
#

It's unavoidable in this instance unfortunately, the vehicle that Npcs can path around is a major component of the game. Maybe later down the track we can keep the vehicle stationary and move levels around it but I'll keep an eye on performance. Thanks!

hardy geode
#

you could split the vehicle internals to its own navigation map and manage the transition between the main map and the vehicle map. This way you could keep both static.

muted island
#

Thanks for the help. I have it set up like this, with a navigation region for the level set to layer 1, and the vehicle has a separate navigation region set to layer 2. Npcs can path on layer 1 and 2 when they are outside, but when they enter the vehicle they are reparented and their navigation agent is set to only look at Layer 2.

Is that kind of what you meant?

hardy geode
#

the navigation_layers are a different thing, they only control which polygons a path search uses, but all the polygons are still smashed on the same navigation map causing conflicts and other problems should they overlap.

#

what I mean is having a dedicated navigation map instead of using the navigation_layers. Each map updates on its own when things are changed, that way you can avoid updating everything all the time. The downside is that you need to connect those 2 maps for gameplay your self and manage the transitions between them

muted island
#

Ah I see! I'm not super familiar with the navigationserver2D but at a glance it seems like I can use this code to create the new map and set the region to it:

var newMapRid = NavigationServer2D.MapCreate();
NavigationServer2D.RegionSetMap(vehicleRegionRid, newMapRid);

Handling the transition from one to the other doesn't seem too difficult either, the vehicle docks in the same place every time it parks, so I can set a node as an entry point and then move and slide the npc onto the vehicle.
Congrats for your work on the 4.2 release btw!

hardy geode
#

yes, you can still design your stuff with the editor but then in script, e.g. in _ready(), you need to switch your region to the other map, there is no gui for that in the editor.

#

if you write a custom "NavigationAgent" script that uses the NavigationServer for path queries directly you can also translate the positions so bascially do the path search on a static "vehicle" navigation mesh that is somewhere offscreen and transform it back for your agent. This way you can place the vehicle visually everywhere without ever moving the navigation mesh and paying the performance cost for syncing the entire navigation map.