Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with pathfinding?

Asked by 8 years ago

Ok so i want to implement custom pathfinding to better fit my game and i read up on the algorithms on the roblox wiki and i have a few questions about the code and all so below is the puesdo code of the best-first algorithm so if anyone could answer my questions below or break down what is happening here that would be awesome.

function best_first(start, finish)
    closed = set({})
    open = set({start})

    score_of = {}
    score_of[start] = calculate_heuristics(start)

    while not open.is_empty do
        -- find node with minimum f
        current = min(open, function(node) return score_of[node] end)
        if current == goal then
            --reconstruct the path to goal
            return create_path(current)
        end
        closed.add(current)
        open.remove(current)

        for neighbor in current:neighbors() do
            if not closed.contains(neighbor) then
                --calculate the heuristics for neighboring node
                score_of[node] = calculate_heuristics(neighbor)
                --add neighboring node to open set
                open.add(neighbor)
            end
        end
    end

    -- there is no path to the goal
end

so now onto my questions

first what is a node exactly i think its the voxel that is being checked but i could be wrong and how could that be implemented in roblox?

second i am confused about the closed and open tables does closed have the path that is used or does open?

third if there is no path to the goal is there a way to recalculate it and get a different path or will this method check all possible paths?

thanks for the help.

Answer this question