Just what it says on the can: everybody speaks about the A* project like it is the solution to 2d pathfinding, yet all the examples I find use 3d colliders. This seems… intuitively wrong to me. Am I missing something?
Hi @AidanofVT
I don’t know what you’ve been reading or watching… you only need abstract nodes and connections, there is no need for anything else.
Nodes can be in free-form pattern, or arranged to grid, to be used as navigation for tilemaps. It makes no difference to algorithm, if you are using 2D or 3D, although 2D grid is the easiest one to create IMO.
Check out Red Blob Games / Amit’s page - he has probably the most extensive archive of A star articles (and other similar algorithms like breadth-first, Dijkstra).
Edit: I’m not sure if you were just referring to using pre-made assets or if you are going to build one yourself, of course it might be that some Asset Store asset might have limitations.
As I understand colliders are often just a way of conveniently determining obstacle vs not obstacle. Because the shapes of your walls/objects/etc may be different than the A* grid, there needs to be a way to translate one to another. This is done by raycasting the center of the grid position. If that’s not what you want, you can find and change the process by which obstacles are detected to not use colliders. So instead of raycasting a cell to check whether there’s a collider there, lookup from your own data structure that says whether that cell is an obstacle or not. If the concern, however, is 2D vs 3D colliders, it doesn’t really matter: obtaining whether an obstacle is in an A* cell is in principle the same.
I think I didn’t make myself clear. I do understand the principals of the A* algorithm, but I’m trying to save myself some trouble by using this plugin: A* Pathfinding Project
I did find this tutorial which seems to be what I’m looking for, but I’m unable to replicate its example. I follow all the steps through the first four minutes, but when I hit scan it doesn’t recognize the obstacle. Here are some images of what I’ve got:
Might be because the A* is targeting Obstacle Layer Mask : “Obstacles” whereas your collider may not be using that same mask or might need you to set it up so that two are the same. If that’s not it, you may also want to consult the Example Scenes or obtain them because a package like that should have them for 2D.
@Lo-renzo Thanks for the tip, but I managed to get it working just through a few hours of trial and error.
You might want to explain what was wrong and how you fixed for people who might come here through search engines.
Hi, i also watched the tutorial you linked and saw your screenshot with the “Mesh-like” A* -Grid. I was wondering how you got that, since in the tutorial its completely rectangular.
Future newbies who find this thread and are confused by that tutorial: if you, like me, don’t know what a tilemap is, you definitely aren’t using one! You cannot just slap the tilemap collider on any old sprite! Instead, use a 2d polygon or 2d circle collider. Also, be sure to check the “Use 2d Physics” box, and do not offset the layers at all. Put the A* grid graph, the obstacles, and the pathfinding agents all at the same depth.
@Vollkh I don’t understand your question. To me they both look like rectangular meshes.
Hi @AidanofVT
Maybe I late to the party, or irrelevant. But yes, its possible to use 2d collider for navmesh in unity 2019.3.
Here is how its done GitHub - h8man/NavMeshPlus: Unity NavMesh 2D Pathfinding