[size=1]Approved by Vorlias![/size]
Some of you might remember this plugin that I made a while back.
However it was very buggy and far from user-friendly (un-descriptive errors, annoying dialogs…)
So I decided to rewrite the entire plugin from scratch, and here we are!
Plugin in action:
Usage:
-
First you need to use the “Place Nodes” -plugin to place some nodes around the map.
These nodes will later create the walkable paths so make sure to only place them in areas where the NPCs will be able to walk. -
When your nodes are ready, use the “Recalculate Nodegraph” -plugin which will compile the nodegraph.
If done right, you should now see ObjectValues named “connection” inside your nodes. Your nodegraph should now be ready for use with the pathfinding library -
You can also connect/disconnect nodes manually with the “Connect Nodes”/“Disconnect Nodes”-plugins, if the compiler missed any.
-
If you have a compiled nodegraph, you can use the “Find path”-plugin to play around with the nodegraph.
How to use it: Click any node to set the path’s start location, and then click any other node to find a path
between those nodes. -
Click “Install Module” to install the pathfinding ModuleScript, to use with your NPC’s or whatever you want to use it for, more details inside the module.
Functions:
[b]pathLib.SearchById(masterTable, searchId)[/b]
Description: Returns the node object from a node ID
Returns: instance "node"
Parameters:
masterTable = table containing master node data(returned by collectNodes)
searchId = The ID of the node to search for
[b]pathLib.SearchByBrick(masterTable, brick)[/b]
Description: Returns the ID of a node from a brick
Returns: int "nodeID"
Parameters:
masterTable = table containing master node data(returned by collectNodes)
brick = the node instance to search for
[b]pathLib.CollectNodes(model)[/b]
Description: Parses the nodegraph for the AStar function
Returns: masterTable, mnt_index
Parameters:
model = The model containing all the nodes
[b]pathLib.GetNearestNode(position, returnBrick, dir, masterTable)[/b]
Description: Gets the node that is nearest to "position"
Returns: int "nodeID" OR instance "node"
Parameters:
position = Vector3
returnBrick = if true, returns instance "node", otherwise returns int "nodeID"
dir = The model containing all the nodes
masterTable = table containing master node data(returned by collectNodes)
[b]pathLib.GetFarthestNode(position, returnBrick, dir, masterTable)[/b]
Description: Gets the node that is farthest to "position"
Returns: int "nodeID" OR instance "node"
Parameters:
position = Vector3
returnBrick = if true, returns instance "node", otherwise returns int "nodeID"
dir = The model containing all the nodes
masterTable = table containing master node data(returned by collectNodes)
[b]pathLib.AStar(masterTable, startID, endID)[/b]
Description: Finds the shortest path between startID and endID
Returns: table "Path"
Parameters:
masterTable = table containing master node data(returned by collectNodes)
startID = The "nodeID" of the start node
endID = The "nodeID" of the goal node
[b]pathLib.GetPathLength(path)[/b]
Description: Returns length of path in studs
Returns: ^
Parameters:
table "path" = A Path returned by pathLib.AStar()
[b]pathLib.DrawPath(path)[/b]
Description: Draws specified path in 3D space
Returns: Model of all the drawn parts
Parameters:
table "path" = A Path returned by pathLib.AStar()
[code]–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, mnt_index = 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)[/code]