Created
May 2, 2022 18:21
-
-
Save Elmuti/cbf94dce47d3edd3597c5d41fd3b15cd 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
--[[ | |
File: pathLib.lua | |
Author: Elmeri Ferm | |
Description: A useful A-Star based pathfinding library for ROBLOX | |
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/disconnect nodes manually with the "Connect Nodes"/"Disconnect Nodes"-plugins, 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. | |
Functions: | |
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() | |
]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment