I am using a 2D grid graph and was wondering if it is possible for my AI to detect whether using a teleporter is quicker to reach its destination, rather than walking all the way there? I want to do this for the edges of my map, so that the AI reappear on the other side. Any help on this would be greatly appreciated!
Since you have a map with wraparound I’m guessing creating these links using code is easier for you. Take a look at this page for how to add new connections using code: https://arongranberg.com/astar/docs/editinggraphs.html
You can use AstarPath.active.gridGraph.GetNode(x, z) to get the relevant nodes.
If you create a link with a cost of 0 (or at least a very low cost) then you will also need to modify the A* Inspector -> Settings -> Heuristic setting. It needs to be set to None because otherwise the A* algorithm assumes that moving towards the goal is usually better than moving away from it, so it will usually never even consider moving in the opposite direction.
See also https://arongranberg.com/astar/docs/pathfinding.html#Heuristic
Note however that the agents will not automatically teleport to the other side of the map. That you’ll have to do yourself. The agents will just think that “oh, now I apparently need to walk to the other side of the map, let’s turn around”.
Maybe I am a bit slow, but could you give a more detailed explanation on how you would make this work? I turned off the heuristic setting but if I position a nodelink next to the start position and a nodelink next to the end position, it should take the nodelink (with 0 cost), however it doesn’t do that. I believe it is because the distance between the nodelinks are a part of the equation, which makes the total distance greater if using the nodelinks.
Hi @aron_granberg This is the setting that I have made in my game, and even though the “portals” are connected with nodelink2 and the cost is 0 (and heuristic setting is none), it won’t choose to use the “portals”. I am guessing that it takes the portal distance into the measurement which makes that route longer.
Do you think you could show a screenshot of the pathfinding result when you have A* Inspector -> Show graphs enabled, A* Inspector -> Settings -> Debug -> Show search tree enabled and graph coloring mode set to G.
@aron_granberg I am definitely having the same issue but I definitely have the heuristic set to none
You can see the green line in the middle, so the nodelink2 seems to be working, but my enemies never choose to use it. Has anything changed in the recent versions?
For anyone in the future, our settings had to be changed in various places, not just the Heuristic for this to work which wasn’t ideal and also needed to call RichAI.Teleport so that when they teleport to stay there and not to snap back to the grid.