How to make NavigationAgent2D to use a Warp Point to go faster

Godot Version

4.X

Question

Yesterday I learnt that NavigationLink helps perfectly to trace paths for NavigationAgents that could be unidirectional. For example for making a bot to go through a slope but climb from the stair.

Today I tried to make a NavigationAgent to enter a Warp Point from the SHOP near Point A to Point B, which is very far from the SHOP

It seems the AI is trying to go from A to B through the impossible path (red path in black area) instead of the warp point (the pink path)

Is possible for NavigationAgent and NavigationLink to resolve a path that could be much easier (or even possible) to traverse through a Warp Point?

I’ve set this config in the NavigationLink:
Start Point & End Point: the GLOBAL COORDINATES of the tilemap
Travel cost: 0
enter cost: 0
Navigation layers are set to the same navigation layer of my tiles. This works as I managed to set slopes

Many thanks!

that sounds like you have all “room” created in a single tilemap?
well why dont you teleport the navigation agent node to “room” B, set the target to point B, then have it recalculate the next points again

Correct

Not sure if I understand you. Navigation agent will teleport to room B, but they need to reach the door first. On touch they would be automatically teleported, then they will recalculate the path to the current target

The issue is that navigationagent does not understand that they can travel from A to B by touching the portal. This works when creating slopes and making the NavigationAgent to understand that falling from a slope is faster than using the stair. The strategy should be the same in this case, which doesn’t seem to work.

they dont, so you should actually make a list of target position this navigation agent will go

Thanks for helping!

What do you mean with a list?

What kind of list/node you need to define to make the AI know that they can travel to go quicker? Isn’t Navigation link designed to make the AI know they can move through the map using shortcuts like warps, slopes and so?

No, teleporters are not reliably possible with the default AStar pathfinding or with the default NavigationAgent node.

What you need to do is create a highlevel mapping of your teleports with their cached path cost. Then, when your agent wants to query a path you check both your cached teleport paths and the normal paths and direct it to whatever path is best from its current position.

Ohh :frowning: many thanks. I saw this demo when navlink node was designed and I thought it would solve exactly this issue.

I’m unsure how this cached system would be decided. so I would need to have a list of teleport paths, or points. Then when I check for getting the next path position I would check if the current path is near a teleport that ends near the goal, and then decide to take that path instead of the calculated by the navigation agent or similar.

Would this be accurate?

Thanks!

The most basic version is that you compare the path length of agent position to target position with the combined path length of agent position to teleport begin and teleport end to target position.

When the teleporter path is shorter you store the target position of the agent and set the agent target position to the teleport begin. After the teleport is used you set the old target again.

If you have a larger and more complex navigation mesh doing this for every query can be costly and at that point you need to cache things or map things e.g. map the teleports to the navigation regions in a dictionary to first do a highlevel check how an agent can go from region to region instead of searching the entire navigation mesh multiple times for each teleport.

I think it would work. I thought this could be solved by some kind of navigation node. For now, I think I can sort out this way.

Many thanks!