✓ Accepted answer
The following code is little sniplets from my npc George, hes quite advanced. You can find him in person here:
https://www.roblox.com/library/331847610/Its-George
He can also (or could) drive vehicles and did i mention he can also get travel sick! :P
lol anyway the basics of his path finding is below. Your more than welcome to download him and disect his brain (he's kinda used to me doing it! lol)
Code:
local Self = script.Parent
local ME = Self.Humanoid
local Path = {}
local CurrentPoint = 1
local function computePathtoV3(Target)
local PFS = game:GetService("PathfindingService")
local path = PFS:FindPathAsync(Self.HumanoidRootPart.CFrame.p,Target,1024)
return path:GetWaypoints()
end
myPos = TargetPos
Path = computePathtoV3(myPos)
local atEnd = false
while true do
if(#Path > 0 and AtEnd == false) then
local Dist = (Self.HumanoidRootPart.Position - Path[CurrentPoint].Position).magnitude
Self.Humanoid:MoveTo(Path[CurrentPoint].Position)
if(Dist < 3) then
CurrentPoint = CurrentPoint +1
end
end
if(CurrentPoint >= #Path) then
AtEnd = true
end
wait()
end
Each time your npc gets to the end of a path you would clear the Path table and resetting the path index (CurrentPoint ) to 1
aka:
Path = {}
CutrrentPoint = 1
Hope this helps! :)
4 comments
what line does the normal pathfinding start? all I can find seems like just vehicle stuff (in the full model you sent)
also the script you sent doesn't match anywhere in the model you sent me...
yeah the script i posted here is the path script section. Its in the Brain script inside him. the computePathtoV3 is at line 145 and look right down the bottom of the script for where he walks the path.
Just search for the varable "Path" and you'll see