Simple to use node based A* pathfinder API and Plugin

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

Here’s the plugin

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)

Neat. I was going to do something like this with A* or Djinkstra’s but then the official service came out. Its cool to see people making plugins like this that can really assist with game development. Roblox seems to be gradually becoming a professional game development platform it seems, in my mind. Gradual evolutions lessen the distinctions between it and other. 3D game dev engines (Besides the obvious visual distinctions that will always exist)

I think it’s RBXDev that changed it all for me. Serious discussion is just not an option on the regular roblox forums, and if I had posted this on the regular forums, I bet less than 10% would’ve even known what pathfinding means

Bumping because added a lot of features :slight_smile:

I still prefer VolcanoINC’s version sorry
[size=1]loyalty[/size]

[quote] I still prefer VolcanoINC’s version sorry
[size=1]loyalty[/size] [/quote]Except the plugin of his is broken. :stuck_out_tongue:

[quote] I still prefer VolcanoINC’s version sorry
[size=1]loyalty[/size] [/quote]Except the plugin of his is broken. :P[/quote]

For some reason when I enable this plugin and try to play solo and error pops up saying something about a Debugger. When I disabled the plugin the error stopped happening. Any idea why?

EDIT: Stopped happening. It only happened in the previous version for me.

EDIT 2: Never mind… Plugin still crashes my play-solo.

That is not related to my plugin

I decided to bump since I added some extra extra functionality!

Due to users demands, I added the ability to remove nodes, and the module no longer annoyingly autoinstalls into workspace everytime you start up a new place, you can simply insert the module with a press of a button :slight_smile:

Got rid of all (atleast most) annoying print statements causing output clutter