A* Nodegraph based pathfinding plugin/module

Some of you might or might not remember this plugin that I made a while back.

However I decided to re-post this on the new forums because the old thread is kinda broken and reliant on BBCode.

So 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.

Module API reference: (might not cover every available function)

pathLib.SearchById(masterTable, searchId)
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

pathLib.SearchByBrick(masterTable, brick)
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

pathLib.CollectNodes(model)
Description: Parses the nodegraph for the AStar function
Returns: masterTable, mnt_index
Parameters:
model = The model containing all the nodes

pathLib.GetNearestNode(position, returnBrick, dir, masterTable)
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)

pathLib.GetFarthestNode(position, returnBrick, dir, masterTable)
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)

pathLib.AStar(masterTable, startID, endID)
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

pathLib.GetPathLength(path)
Description: Returns length of path in studs
Returns: ^
Parameters:
table “path” = A Path returned by pathLib.AStar()

pathLib.DrawPath(path)
Description: Draws specified path in 3D space
Returns: Model of all the drawn parts
Parameters:
table “path” = A Path returned by pathLib.AStar()

Usage Example:

--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)
8 Likes

This looks like a great idea. But for anyone who comes across, it seems that it crashes Roblox studio. I am not trying to bump this but my studio is now unusable after installing.

Remove it from your directory directly (but do not permanently delete it; you may have to restore it if it causes unintended behaviour to your launcher). Go to %appdata%\..\Local\Roblox\InstalledPlugins, search for the folder that matches the id of the plugin and delete it, then try opening Studio again.

1 Like

Didn’t work, it wont even show up in the folder. This was after reinstalling. Are plugins internet replicated now?

Saved to the Cloud actually, yes. Check the directory of your UserId instead?

%appdata%\..\Local\Roblox\95587901\InstalledPlugins

1 Like

Still crashes as soon as I start studio. I tried deleting all my plugins as well :frowning:
As soon as I start studio they come back and crash

I have no other fix attempts. Consider filing a crash report via #platform-feedback:studio-bugs with PA. We will able to provide you information and support about developing a crash report and including necessary details which will then be forwarded to the Studio Crash Reports team.

1 Like

After some digging, I was able to get things back to normal. I essentially had to edit the plugin file (with notepad++) and corrupt the file by editing it. Save it, then relaunched studio to uninstall it. Thanks!

1 Like

Unlisting as this plugin appears to no longer function as intended. Will leave open in case there’s an update and it can be listed again.

Sorry for the late response, freeze on load has been fixed