I need to make an enemy NPC that follows a player, but also avoids walls and obstacles. I want it so that it can't get stuck by a player, and keeps on moving.
COMMUNITY QUESTION
How can I make an NPC that follows a player, avoiding walls (Smart NPC)?
1 answer
I've used basic pathfinding before, here's something useful:
local service = game:GetService("PathfindingService")
local humanoid = script.Parent
local torso = script.Parent.Parent.Torso
local finishPosition = nil --Change this to the nearest players torso
local path = service:ComputeRawPathAsync(torso.Position, finishPosition, 512)
local points = path:GetPointCoordinates()
for p = 1, #points do
repeat
humanoid:MoveTo(points[p])
humanoid.MoveToFinished:wait()
until (points[p] - torso.Position).Magnitude <= 4
end
Have fun scripting!
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
http://wiki.roblox.com/index.php?title=Pathfinding
I was just about to comment that
^ qq
If this has been answered, please mark it as answered, thanks.
http://wiki.roblox.com/index.php?title=Making_a_Patrolling_NPC