# Simple Pathfinding 2

Simple pathfinding script 2
unknown
lua
3 years ago
1.1 kB
4
Indexable
Never
```local a=game:GetService("PathfindingService")
local b={} for _,_ in pairs(workspace:GetChildren())
do if _.Name=="Node"then b[#b+1]=_ end
end for _,f in pairs(workspace.Cthulu:GetChildren()) --the name of the AI
do wait(.1) Spawn(function()while wait() do
local _=b[math.random(1,#b)]
local _=a:ComputeRawPathAsync(f.Torso.Position,_.Position,500)
if _.Status==Enum.PathStatus.Success --found its way yay
then local e=_:GetPointCoordinates()
--thinking..
for _,b in pairs(e) do
local a,c=workspace:FindPartOnRay(Ray.new(b,Vector3.new(0,-10,1)))
if a then b=c e[_]=c end
end local b=false
local _ for a=1,#e,2 do local c=e[a] if b then break end local d = 0
repeat d=d+1
if d>100 then b=true
break end f.Humanoid:MoveTo(e[math.min(#e,a+1)])
if c.Y>f.Humanoid.Torso.Position.Y-1
then f.Humanoid.Jump = true --jump
end _=(c*Vector3.new(1,0,1)-f.Torso.Position*Vector3.new(1,0,1)).magnitude wait()
until _<5
end else f.Humanoid:MoveTo(f.Torso.Cframe*Vector3.new(),0,05))
end end end) end
```