(Legacy) SimplePath - Pathfinding Module

Update 0.23:

  • Fixed a bug involving NetworkOwnership.
2 Likes

coolio!

by the way, i have a suggestion:
maybe you should add an option that when enabled, makes the pathfinding NPC try their best to go to a player/humanoid npc and have the humanoid be customizable, because it is kinda difficult to have it chase NPCs due to the fact that i have to manually edit the code and it only chases npcs to their last position and it’d be quite helpful if this was added

great module though! keep up the good work

1 Like

Thanks for the feedback. I will definitely consider adding that feature soon.

Update 0.24:

  • MAJOR FIX: Spamming Path:Run() and transition to new path is now seamless!
  • Fixed Path:Stop() from executing multiple times.
  • Fixed handling of more NetworkOwnership errors.
  • Added a new feature; added IgnoreTimeout parameter for Path:Run() (see api).

You should make this more compatible with bigger Humanoids. I tried using it on a character that is 1.5x bigger than the average player, and even after changing the AgentHeight and AgentRadius, the character would walk backwards to the starting node every time I would change its goal. But, I found a workaround.

path.InitialPosition = script.Parent.Torso.Position + (goal.Position - script.Parent.Torso.Position).Unit * 2

Full while loop:

local path
while true do
	path = SimplePath.new(script.Parent, {AgentHeight = 7.5, AgentRadius = 3, AgentCanJump = true})
	
	game:GetService("RunService").Heartbeat:Wait()
	local goal = FindNearestTorso(script.Parent.Torso.Position)
	if goal then
		path.InitialPosition = script.Parent.Torso.Position + (goal.Position - script.Parent.Torso.Position).Unit * 2
		path:Run(goal.Position, false)
	end
end

Update 0.25:

  • Path:Run() now returns true if the path is successful (make sure to handle this).
  • Fixed bug when pathfinding for humanoids with different sizes.
  • Removed the previous feature for IgnoreTimeout and made it built-in.
  • Fixed error that stops the Humanoid randomly.

Try now and let me know how it goes.

1 Like

Looks promising, gonna definitely check it out!

This is a pretty cool module! Just a question though, how would I make a pet (npc) that is following a player know when to jump or not?

Hey, thanks for the feedback! When you execute the Run() function, the module calculates the timeout of the rig using walkspeed and rig size. So say if the rig needs to jump in order to reach the next waypoint. In this case, it can be detected by the module when the rig doesn’t reach the next waypoint within the calculated time. If there’s a timeout, the rig jumps automatically. So you don’t need to worry about making the pet jump. It will jump itself.

Edit: I had to add this feature since roblox autojump doesn’t work always and is unreliable.

1 Like

Oh thank you! Thank you for letting me know.

Edit: Actually, I solo’d the code once and tried to make the pet jump over a gap in my game, and it didn’t jump over, it just fell off…

Oh I thought you meant if it jumps over an obstacle like an inteference blocking the path. In that case, the module doesn’t make the rig jump over gaps. It doesn’t because roblox’s pathfinding service does not support that.

Oh ok, thanks for letting me know either way.

Does this work with custom rig and named Humanoid?

Yes, it works with custom humanoids of different sizes.

I meant custom humanoid name. And if no i fixed it.

Do you have to manually handle when the NPC needs to jump or does the module manage that?

The module uses Roblox’s pathfinding service which has autojump enabled by default. But sometimes, in the case where the humanoid gets stuck because of some kind of obstruction and there’s a timeout for the MoveTo function, the code makes the humanoid jump. This is an extra feature I added because the humanoids get stuck sometimes even with autojump.

2 Likes

@GrayzcaIe I love this module and I think it’s really helpful. I think you should add a “trail” function or something like that after the NPC moves to that spot.

Hmm, you might need to elaborate more on the use case and what it does as I’m not entirely sure what you mean.

Also, be sure to use the latest version of SimplePath if you aren’t already, this one is an older deprecated version.