Firstly: I am trying to learn how to make fighting npc’s so I have no idea if pathfinding is even the right way, I dont really want to watch a tutorial for it because I want to learn it not copy-paste it.
so, I have built this pathfinding system
but randomly the npc’s move in circles
I have looked for posts but never found one that has a solution.
I have tried:
using lookat() then moving by one stud – caused way too glitchy movement
changing agent settings – did nothing
reading forums – did nothing (none had solutions)
The problem might be but I do not know how to fix:
I shouldnt be using pathfinding
I am overriding paths – (idk just saw that in a post)
Roblox’s pathinding is bad
the following code is not the full script, although I will note it’s inside a wait() loop,
hrp is the npc’s root part and item is the targets root part.
You should use something like a loop and not one static Number since there could be multiple waypoints and not just one to go trough. It could looks like this:
local success, errorMessage = pcall(function()
path:ComputeAsync(hrp.Position, item.Position)
end)
if not success then warn(errorMessage) return end
local Waypoints = path:GetWaypoints()
if Waypoints then
for i, waypoint in ipairs(Waypoints) do
script.Parent.humanoid:MoveTo(waypoint.Position)
script.Parent.humanoid.MoveToFinished:Wait()
end
end
So it seems after a day and looking back on my code I don’t think I needed to pathfind, my new code is just script.Parent.Humanoid:MoveTo(item.Position, hrp) via moving to the targets root itself but making the npc a bit dummer which is good enough for my standards