- Home /
Lost in Pathfinding again
With some awesome help from whydoidoit and unitygems, I was able to make some hexagonal pathfinding : http://www.alucardj.net16.net/examples/StrategyGridPath0-1.html
Built after help on this question : http://answers.unity3d.com/questions/361204/lost-in-pathfinding.html
Before the new year, that turned into this little game : http://www.alucardj.net16.net/examples/StrategyGrid1-0.html
So I thought I was ready to develop my pathfinding to a navmesh, but I was wrong : http://www.alucardj.net16.net/unityquestions/WaypointPathfinding1.html
There is something wrong with the way the heuristics are calculated. This can be seen when you select a position on a different height or around an obstacle, the charcter zig-zags his way to the destination. He will get there, just not directly.
I have been over my code until my eyes glaze over, yet I cannot see where I am assigning the wrong heuristic value, or or simply adding the wrong thing to a list, or not removing something from a list.
I need an expert eye, someone with experience in this type of pathfinding to help me see where I am making mistakes leaving my character to pick zig-zag paths. He absolutely gets there, and uses the virtual paths, it's just the zig-zagging that has me stumped. (nudge-nudge, wink-wink, I see you have some spare time at the moment whydoidoit !).
If anyone can help me realize where I am going wrong with my heuristic calculations, then my joy will be indescribable =]
Here is the script : http://www.alucardj.net16.net/unityquestions/TroopScript.js
And here is a package of the project : http://www.alucardj.net16.net/unityquestions/WaypointPathfinding1.unitypackage
lmb shows my virtual navmesh, rmb to move.
Was going to read your question, but got stuck playing the game ;)
In A* pathfinding, this sort of behavior sometimes happens, so to combat it, I give one axis a slightly higher "score" than the other axis. Can something like this be applied to your algorithm?
Heh, no worries merry_christmas, it actually feels good that someone apart from me has played one of my games. As you can see, it is very much an early prototype. All my projects get to this stage, then I get bored of looking at it, or interested in something else, so I havn't got a single game that's finished and polished to completion. The map editor definitely needs multi-select which I know how to do. $$anonymous$$aybe if you think it's worth it I shall start working to make it a real proper game. For me that project wasn't really about the RTS, more the pathfinding, and the random map generator and hexagonal grid procedural mesh. I was going to develop this to voxels and have destructible environments.
Dracorat : thank you for the suggestion, I shall certainly take a look at increasing the heuristics for diagonal navPoints, and let you know the results. That is a really good suggestion =]
I've made a very similar hex based game and pathing system before. It looks like you could be have any number of small bugs
You are not calculating your heuristics properly
You are not calculating your actual cost properly. It seems to get confused if co$$anonymous$$g from specific sides.
You may be running into floating point problems. This seems unlikely, but it produces this kind of erratic pathing
I once ran into this where because of a program$$anonymous$$g bug the AI could only go to five of the six sides. I felt really dumb.
I would recommend making a gizmo to show the pathing cost of going between every node. Something like a colored arrow showing the transition cost. It is maddening to debug AI without graphical debugging tools.