A* how make natural look path?
- by user11177
I've been reading this:
http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html
But there are some things I don't understand, for example the article says to use something like this for pathfinding with diagonal movement:
function heuristic(node) =
dx = abs(node.x - goal.x)
dy = abs(node.y - goal.y)
return D * max(dx, dy)
I don't know how do set D to get a natural looking path like in the article, I set D to the lowest cost between adjacent squares like it said, and I don't know what they meant by the stuff about the heuristic should be 4*D, that does not seem to change any thing.
This is my heuristic function and move function:
def heuristic(self, node, goal):
D = 10
dx = abs(node.x - goal.x)
dy = abs(node.y - goal.y)
return D * max(dx, dy)
def move_cost(self, current, node):
cross = abs(current.x - node.x) == 1 and abs(current.y - node.y) == 1
return 19 if cross else 10
Result:
The smooth sailing path we want to happen:
The rest of my code: http://pastebin.com/TL2cEkeX