Wrap paths around plane

Hey,
first I would like to thank you for this genius contribution.
Imagine a world map, where you can travel off the border. We need to wrap the path around the map, so if an agent leaves the map at the right side for example, he needs to come out on the left side of the map (think pacman). Is there an easy way to accomplish that?

Thanks in advance,

Torsten

I think this should work.

`
public void Start () {
GridGraph gg = AstarPath.active.astarData.gridGraph;

int cost = gg.nodeSize * Int3.Precision; // Standard cost

// Link X
for ( int x = 0; x < gg.width; x++ ) {
    gg.nodes[0*gg.width + x].AddConnection ( gg.nodes[(gg.depth-1)*gg.width + x], cost );
    gg.nodes[(gg.depth-1)*gg.width + x].AddConnection ( gg.nodes[0*gg.width + x], cost );
}

// Link Z
for ( int z = 0; z < gg.depth; z++ ) {
    gg.nodes[z*gg.width + 0].AddConnection ( gg.nodes[z*gg.width + gg.width-1], cost );
    gg.nodes[z*gg.width + gg.width-1].AddConnection ( gg.nodes[z*gg.width + 0], cost );
}

}`

Also, you will have to disable the heuristic in A* Inspector -> Settings since the heuristic assumes that moving away from the target is not that good.

I´ll try it out and let you know if it works. All thumbs up, you´re great!

No errors, but the agent changes his direction when he comes to the border (as expected). However, it should travel over the edge and come out on the other side. So I think I have to translate him by myself to the other side, when he reaches the border. What do you think is the best way to do this? (Read: How to determine if he has reached the border?)

Thanks again

What I´ve done to get the desired behaviour: I check if the agent reaches the border, then I set his position to the other side and recalculate the path. Now everything works as expected! Again, thank you very much. :slight_smile: