Skip to content

Instantly share code, notes, and snippets.

@Elmuti
Created May 2, 2022 18:21
Show Gist options
  • Save Elmuti/9a554e150ee67268beadd13018010cf2 to your computer and use it in GitHub Desktop.
Save Elmuti/9a554e150ee67268beadd13018010cf2 to your computer and use it in GitHub Desktop.
--For this code to work, you need to have a compiled nodegraph in workspace named "Nodes".
--You must also have parts called "START" and "GOAL" in workspace which will be used to find
--the start and goal locations for the path. See the documentation inside the module for more information.
local pLib = require(workspace.PathfindingLibrary)
local nodeModel = workspace.Nodes
local masterTable = pLib.CollectNodes(nodeModel)
local startID = pLib.GetNearestNode(workspace.START.Position, false, nodeModel, masterTable)
local goalID = pLib.GetNearestNode(workspace.GOAL.Position, false, nodeModel, masterTable)
local path = pLib.AStar(masterTable, startID, goalID)
--Let's print all the node IDs of the found path
local num = 0
for _, node in pairs(path) do
num = num + 1
warn("Node #"..num.." on path: "..pLib.SearchByBrick(masterTable, node))
end
--Let's draw the path!
pLib.DrawPath(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment