Created
May 2, 2022 18:21
-
-
Save Elmuti/9a554e150ee67268beadd13018010cf2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--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