How to make natural-looking paths with A* on a grid?

Posted by user11177 on Game Development See other posts from Game Development or by user11177
Published on 2013-11-01T21:13:31Z Indexed on 2013/11/02 22:20 UTC
Read the original article Hit count: 255

Filed under:
|

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:

enter image description here

The smooth sailing path we want to happen:

enter image description here

The rest of my code: http://pastebin.com/TL2cEkeX

© Game Development or respective owner

Related posts about path-finding

Related posts about python