Search Unity

Pathfinding with waypoints

Discussion in 'Scripting' started by DarkSoul, Jun 29, 2010.

  1. DarkSoul

    DarkSoul

    Joined:
    Dec 24, 2009
    Posts:
    37
    Hi.
    I'm creating a simple pathfinding with waypoints, but, I have a problem: I don't know create the path between point A and the point B.
    I don't know how to create the more fast path to the point B. The first screen show my waypoint system, the second screen, show what I try to do. I don't want other pathfinding system, because are more complex and I want a simple system. Any help or ideas? I'm very lost.
    Thanks!
     

    Attached Files:

  2. ackyth

    ackyth

    Joined:
    Oct 29, 2009
    Posts:
    146
    Google A* or AStar pathfinding, it really is the best and most simple way to find a path.

    Takes some time to wrap your head around it but its really simple to code a basic pathfinder. (geting it to run supper fast is the harder part) but if you have only a few things trying to path at a time you dont really need to tweak it for speed.

    That said, You need to make a node class with info like

    surrounding nodes (array)
    parent node

    and then another class as the pathfinder that when the game starts have it find all nodes and place them in a array.

    when pathing

    find nerest node to charactor
    add that node to a openlist (another array)
    find end node (closest to endpoint)

    get connecting nodes from that node
    add them to open list
    add start node to closed list

    look though open list and find lowest cost node

    cost is easyest to add up by takeing the distance from current node to "this" node and then adding the distance from current node to end node and then take that number and run it vs all the other nodes in openlist

    take the lowest cost node and get connecting nodes add them to open list

    add node to closed list and set the node.parent to current node.

    loop untill we find end node (goto checkout)
    or openlist is empty (path fail)

    when rebuilding the path just take the end node and get the parent node then take that node and get the parent of it and so forth untill you get to your start node.

    ^^Above is a ruff idea on how to do it has been a few months since I last coded my A* so it may have a few holes.