I have a 2D grid of tiles. I assigned the ones I want to be obstacles in a different Layer and fed that info to the A* script. I added an AI object with “AI Lerp” script on it and assigned a target to it. As you can see in the link below the behaviour is not as expected and the path ends in the wrong direction. Yellow is AI, Blue is the target:
It looks like your graph has some odd configuration, all rows of the graph seem disconnected from each other. Have you checked out the 2D tutorial? https://arongranberg.com/astar/docs/pathfinding2d.html and the 2D example scenes?
Yes, I followed the 2D tutorial exactly. The tiles are not disconnected, I’m just changing the localScale so they appear as separated by a stroke.
Yes, but in the middle of the rows I can see lines of different colors.
See also the recommended configuration for the AILerp script depending on what kind of movement you want: https://arongranberg.com/astar/docs/ailerp.html
Those lines are nothing, they only appear in the editor window. They come and go as I change the window size.
Well. They look suspiciously like the visualization of the grid graph with the ‘Show Connections’ mode enabled and the ‘Show Surface’ mode disabled and you have rows that are disconnected from each other.
Can you try to move the target down a few units and see if it manages to find a path that crosses multiple rows?
Do you think you could post a screenshot of your grid graph settings?
Also do check out the configuration recommended in this link that I posted earlier: https://arongranberg.com/astar/docs/ailerp.html, in particular I think you want to set Seeker -> Start End Modifier -> Start Point and End Point to ClosestOnNode (not quite sure what movement you want though, so do check the link for an alternative).
Ok, So I created a new project and redid everything. Now it works fine without obstacles, but after adding obstacles, it can’t find a path around it.
So your rows are indeed separate and not connected to each other, you can see the big warning in your graph settings that complains about this. It also looks like you are using a pretty old version (earlier than 4.0 at least), because in newer versions it is not even possible to configure it that way (as it was a common source of confusion). If you can I would recommend that you update to a newer version because there have been many improvements done for 2D pathfinding.
It is possible that there are also some fixes that could affect the movement of the AILerp script in 2D, but I’m not quite sure.
I downloaded the newer version 4.2.4 and now it works perfectly fine. There are no more confusing lines and the debugging is more clear. And no, the tiles were not separated either horizontally or vertically, I don’t know why that warning was showing, it seems like a bug in the older version. I imported the new version without even touching anything and it just worked.
Great that it works!
What the old version did was that since you had specified (or maybe it was the default) a max climb of 0.4 and the climb axis as Y, it would not connect adjacent nodes if they had a y coordinate difference greater than 0.4. This would result in that your rows were disconnected from each other. In the new version the climb axis is always the up direction of the graph, so if you rotate it to lie in the 2D plane it will be the Z axis and this issue would not happen.