SimplePath - Pathfinding Module

tried this but they’re still just standing in place and jumping, i used
character:SetPrimaryPartCFrame(CFrame.lookAt(HRP.Position, nearest.HumanoidRootPart.Position * Vector3.new(1, 0, 1) + HRP.Position * Vector3.new(0, 1, 0)))
to make them look at the player

additionally, if i put it outside of the code block including the path:Run() and inside a heartbeat event it will move the npc but at a very slow pace

idk about that code but all I did was CFrame.new(npc.primarypart.pos, player.primarypart.pos)

it will move the npc at a very slow pace because you are constantly changing the cframe of the npc,

which is why using the dot product is crucial, you only want the npc to rotate if he goes outside of your fov (dot product condition statements), doing it only when the player is outside of the bounds will negate the slow pace effect

what do you mean thats all you did? i’ve never heard of dot products before so if you have an api link explaining it that would be great.

that cframe.new is the goal cframe I used, and all I did was tween the hrp when the player was outside a given fov condition. (cause i think its natural looking rather than instant snapping)

2 Likes

Is pathfinding link supported?

This is the stuff man!
ive had a lot of trouble with robloxs’… questionable pathfinding… but this really works!
i like how it also makes some curves to make the pathfinding more smooth.

I’m not sure why but how do I fix FPS Drop

It made my roblox studio laggy and I don’t know why.

1 Like

I have an attack script for when a npc comes close to a player but after it attack it sometimes just starts flying around and I dont know why I also get spammed with the error “Limit Reached” and I dont know what that error means.

are you using while true do? i think it might caused that error

No I wasnt, I solved it by just not using SimplePathing

Hi, I was reading your reply, have you experimented with the Pathfindiing links and if so have you been able to get it to work for an NPC to open a door?

Thanks

Yes, I was able to get it working, Although minor code changes are needed on the simple path module
I have changed InvokeWaypointReached function to this so I can retrieve Last, Current, Next Waypoints.

I believe the original one only sends the Last and Current waypoints, not the next waypoint. I noticed this since I was trying to check if the current waypoint label was == “Door” and it doesn’t return anything, But the next waypoint does. Although I haven’t fully understood if SimplePath does traverse every single waypoint or skips the Current Waypoint if it’s the last waypoint and goes to the target Position instead.

So, doing this way works. Let me know if you found a better solution. So far this works wonders.

Lastly, Listen for path.WaypointReached:Connect(function(lastWaypoint, currentWaypoint, nextWaypoint) and check it’s waypoint Label
eg: nextWaypoint.Label == "Door" then do the rest.

Hope it helps!

Edit:
One thing to note is to use Agent Parameters when using pathfinding links make sure its weight is 0.001 on Agent Parmaters if its the highest priority to traverse. Never go 0. As you can see my Link is DoorwayEnter.

local AgentParams = {
	AgentRadius = 1.2,
	AgentHeight = 0.6,
	AgentCanJump = false,
	AgentCanClimb = false,
	WaypointSpacing = 2.5,

	Costs = {
		DoorwayEnter = 0.001,
		Walkable = 0.1,
	}
}

When you Enable Show Navigation Mesh in Studio Settings to see the waypoints you will notice the waypoints will stop from the Start of the Pathfinding Link and the last waypoint will be the end of the Pathfinding Link and won’t continue to generate waypoints to the target. I haven’t figured this out yet. But believe this is caused by the module. Work around is just call Path:Run() again when every single waypointReached event.

4 Likes

Sweet thanks for the information!

Then when you are listening for next way point = door, do you then kick off the code to open the door?

which then allows the npc to go through it? (

or do you sill have it so the npc does not collide with the doors, and the door opening is just a visual effect?)

Yes, Since you need to listen to Path.WaypointReached event and call path:Run(target) to continue the waypoints, Instead I call a function to open the door and make the NPC move forward a bit when Waypoint Label is “Door” and do animation, After the animation I call Path:Run(target) again to continue

1 Like

how can i use simplepath to follow the nearest player?

Use this to check repeatedly for the nearest player:

local function FindNearestPlayer()
	while wait(0.5) do
		local found
		local last = math.huge
		for _,plyr in pairs(game.Players:GetPlayers()) do
			local distance = plyr:DistanceFromCharacter(script.Parent.HumanoidRootPart.Position)
			if distance < last then
				found = plyr
				last = distance
			end
		end

		Goal = found.Character.HumanoidRootPart
		return Goal
	end

end
1 Like

Why does this happen when I try to use SimplePath with a custom r15 rig?
(I use Path:Run())

1 Like

I’ve since found the solution to the replied issue. For everyone who utilizes this module, please refer to this post, it may save you a headache in the future:

8 Likes

very good, but how can i do this with something like bodyposition as a example?

1 Like