EDIT:
All (atleast most) annoying prints causing output to be cluttered should be taken away now
I used to have the same pathfinder in a script before, but now I’ve stuffed it all into a single plugin with several tools and a modulescript that you can insert into workspace
If you have any questions, please ask away
Q/A:
Q: Why would I use this instead of PathfindingService?
A: This is a lot faster and much simpler to use on static maps
Q: How much faster is it?
A: This pathfinder takes around 0.0001 seconds average to calculate a path on a moderately complex navigation
graph
Q: Anything else?
A: Lots of things you can do with a preset grid instead of dynamic pathfinding, wanna make an NPC patrol around the map? Just make him walk to random nodes. Wouldn’t be as easy with the official pathfinder.
And here’s everything about how to use it:
Usage:
1. 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.
2. 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
3. You can also connect nodes manually with the "Connect Nodes"-plugin, if the compiler missed any.
4. 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.
[b]Functions:[/b]
[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.drawPath(path)[/b]
Description: Draws specified path in 3D space
Returns: Model of all the drawn parts
Paremeters:
table "path" = A Path returned by pathLib.AStar()
Also have some EXAMPLE 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)