While I was working with pathfinding NPCs, I noticed that some commonly used methods such as using Humanoid:MoveToFinished()
in between waypoints makes the character stop or not follow a specific path in a lot of cases, and realised a need for a character control module which is easy to use, configurable, can follow a part/model or pathfind to a location once, and applicable for most cases. That is why I made Pathfinder, I first got the idea from an NPC character I was working on and decided to expand it to an open source module form.
The GitHub repository is the main source for all information related with this module and you can find everything there, plus lots of extras.
While the module is tested and the methods I used were used in a live game before, the module itself as a whole was not. If you experience any issues, please create an issue on the GitHub repository.
What does Pathfinder do?
- Pathfinder uses PathfindingService for waypoints and waypoint actions, which means it supports every PathfindingService features Roblox offers.
- Pathfinder uses custom logic (instead of MoveToFinished) to control the delays the character needs to follow the target, which can be a still or a moving target.
- Pathfinder offers defaults which will be useful for most of the use cases, however, is designed to be configurable.
- Pathfinder offers user-made actions for NPC characters (example, NPC can jump to the target player if the distance is less than an amount).
What does Pathfinder NOT do?
- Pathfinder is not a replacement to PathfindingService. It actively uses PathfindingService to create the waypoints.
- Pathfinder is not made for non-Humanoid or non-character (such as cars) entities. They might or might not work.
- Pathfinder will not work as fast as non-pathfinding character control methods, such as the plain MoveTo.
- Pathfinder will not add new waypoints, although it can skip some waypoints to move without stopping, which means your paths will be as good as your navigation mesh in most cases.
Example usage: (please check the GitHub repository for detailed examples and explanations)
local p = Pathfinder.new(char, {
Target = t,
AgentParameters = { --optional
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true,
AgentCanClimb = true,
PathSettings =
{
SupportPartialPath = true
},
Costs = {
PathfindAvoid = 9999,
Truss = 1
}
},
}) :: any
After this code I would just need to run it with p:Run()
.
This example does not demonstrate moving targets or the optional configurations, the rest is in the repository.
Installation
You can get the module from Creator Store here, for wally and manual installations please check out the GitHub repository.
Issues and suggestions
Before reporting any issues, please set DebugWaypoint = true
on your Pathfinder instance ( DebugMode = true
will also be helpful but if you have many NPCs, the prints might lag Studio) and make sure that the nodes are where you would expect them to be. You might need to adjust your agentParameters or you might need to check your NavigationMesh (File → Studio Settings → Studio → Show Navigation Mesh and enable) and optimize your environment for a more ideal NavigationMesh. If there is something unexpected with your Navigation Mesh, module’s accuracy might also be affected.
If you think that the issue is with the module after checking these, you can report the issues and suggestions to the repository to keep everything organized, however I’ll also respond to this topic.