I just tried to follow a tough tutorial about A* path finding in Unity C#. I have also tried Unity own Navigation & Pathfinding system which is actually quite easy to understand and implement. I am willing to know it that how NavMesh system of unity actually works. Do it also implement the A* algorithm. Further I want to ask that how does A* algorith will work with slope. I implement A* with plane where is no slope.
1 Answer
Here is how a computer will see an a star path find:
As you see, it is just a graph of nodes with certain neighbors. Between each neighbor, there is a "distance", or weight, that connects the two nodes. The algorithm finds a rout between nodes that will have, when all of the path lengths are added up, the smallest possible number.
If you look at a navmesh, all it does is separate the map into a lot of triangles. Every touching triangle represents a neighbor, and the dist between the two neighbors is most likely the distance between each triangle's center point, but there might be other algorithms. And, using this graph, it probably uses a star, maybe with performance optimizations. See here for more info.
On a grid, like the ones you saw in the video, the nodes are the tiles, and the distance is just 1 unit for adjacent and about 1.4 units for diagonal.
Going back to your slope, if you want the agent to be slower on it, then artificially make the number between the nodes larger like:
if (nieghbor has to much of a y-value difference):
neighbor_cost *= 5
For more info on artificially changing the distance between nodes, click here.
Hope this helps. Ask me if you need any more info! =D
-
\$\begingroup\$ Thanks for valueable input. Can i try the video code with slope envrionment? \$\endgroup\$ Commented Jan 2, 2017 at 4:59
-
\$\begingroup\$ @MohammadFaizanKhan I have not seen the video, but I believe that a generic a star algorithm could handle practically anything. Do you want your game to be grid based or navmesh. I think I need more details. \$\endgroup\$ Commented Jan 2, 2017 at 7:45