'Need some assistance with pathfinding [closed]
I´m making a puzzle game which needs some pathfinding to guide selected units to their destination. This is my first time dealing with any kind of pathfinding, so I´ve chosen the aStar method which was the easiest for me to understand. (thanks to this wonderfull page Link). I´ve come quite a way, further than I expected actually but there are still some minor problems.
I could write a long explanation which no one would understand, but instead I uploaded my flash project so you can see: http://www.martinowullems.com/pigsplode/pigsplode%20flash.html
Select a pig and then select a second tile to make it walk there (not the bottom tiles, they're bugged :P). The dark tiles are unwalkable.The red tiles are the ones that belong to the generated path. I seem to be on the right track, I get the feeling I ´m making just a minor mistake. I got the feeling something wrong with selecting the best node (findNextNode function).
I've been staring at the code for way too long and am not making any progress. I've tried looking at other people's implementations, but I always have a hard time understanding other people's work.
Any help would greatly be appreciated, want to move on with the project!
I made a wonderfl version so you can check out and fiddle with the code: http://wonderfl.net/c/hRtO
Solution 1:[1]
In the placeNode() function, in the case that the current node is already on the open list, you aren't changing the parent node when the G value is improved using the new parent node.
//if it is already on the open list - check if it is a better option
if (node.G > parentnode.G + 10) {
//recalculate
node.parentNode = parentnode; //add this line
node.G = parentnode.G + 10;
node.F = node.G + node.H;
}
That may not be the only problem, but it looks like a source of potential errors. Hope it helps.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Connman |
