generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Using Pathfinding on NPC

Previous Thread :: Next Thread 
HatLicense is not online. HatLicense
Joined: 16 Mar 2015
Total Posts: 330
18 Jul 2016 06:35 PM
as of today I thought I'd look a little more into doing stuff with AI for NPCS, I researched PathFinding and came across a ROBLOX Youtube Tutorial which explained very well what pathfinding is and how to use it but It never really gave me any clue as to how I'd use pathfinding in NPCS.

Would anyone be able to explain how I'd use PathFinding to make an NPC go somewhere? I'm aware it would involve WalkTo() and so on but how would I implement PathFinding into that?
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
18 Jul 2016 06:36 PM
--Use pathfinding to get your Vector3.
NPC.Humanoid:MoveTo(Vector3)

Pretty simple if you understand pathfinding.

u sicko!
Report Abuse
HatLicense is not online. HatLicense
Joined: 16 Mar 2015
Total Posts: 330
18 Jul 2016 06:40 PM
What's the difference between a Normal Path and a Smooth Path?
Report Abuse
HatLicense is not online. HatLicense
Joined: 16 Mar 2015
Total Posts: 330
18 Jul 2016 06:47 PM
also:

repeat wait() until script.Parent
script.Parent.Parent:FindFirstChild("start")
pathfinding = game:GetService("PathfindingService"):ComputeRawPathAsync(script.Parent:FindFirstChild("Torso").Position,script.Parent.Parent:FindFirstChild("finish").Position, 200)

script.Parent:FindFirstChild("Humanoid"):MoveTo(???)

I'm not sure what I'd put in the MoveTo...
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
18 Jul 2016 06:50 PM
You put a Vector3 into MoveTo().
Keep in mind though ComputeRawPathtoolazytofinish returns a table.

u sicko!
Report Abuse
HatLicense is not online. HatLicense
Joined: 16 Mar 2015
Total Posts: 330
18 Jul 2016 06:54 PM
I know it needs a Vector but I'm not sure where I'd find it?

How do I combine the Pathfinding with the MoveTo?
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
18 Jul 2016 06:57 PM
So ComputeRawPathAsync() returns a table containing the Vector3s for the path. All you need to do is call it and then it will return it. Then, you just need to iterate through the table and move your NPC to the points:

local pathfinding = game:GetService("PathfindingService"):ComputeRawPathAsync(script.Parent:FindFirstChild("Torso").Position,script.Parent.Parent:FindFirstChild("finish").Position, 200)

for i,v in pairs(pathfinding) do
script.Parent.Humanoid:MoveTo(v)
end


u sicko!
Report Abuse
HatLicense is not online. HatLicense
Joined: 16 Mar 2015
Total Posts: 330
18 Jul 2016 07:00 PM
It's coming up with an error:

bad argument #1 to 'pairs' (table expected, got Object)
Report Abuse
HatLicense is not online. HatLicense
Joined: 16 Mar 2015
Total Posts: 330
18 Jul 2016 07:04 PM
ahh I found it.

repeat wait() until script.Parent
local pathfinding = game:GetService("PathfindingService"):ComputeRawPathAsync(script.Parent:FindFirstChild("Torso").Position,script.Parent.Parent:FindFirstChild("finish").Position, 200)
points = pathfinding:GetPointCoordinates()
while true do
wait(.1)
for i,v in pairs(points) do
script.Parent.Humanoid:MoveTo(v)
end
end
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
18 Jul 2016 07:06 PM
Ok, here is an example from one of my scripts:

local path = game:GetService("PathfindingService"):ComputeSmoothPathAsync(npc.Torso.Position, torso.Position, 512):GetPointCoordinates()
if path ~= {} then
if pcall(function() npc.Humanoid:MoveTo(path[2]) end) then
elseif pcall(function() npc.Humanoid:MoveTo(path[1]) end)then
npc.Humanoid:MoveTo(path[1])
end
end

You should be able to use that.

u sicko!
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
18 Jul 2016 07:07 PM
That should work too though :)

u sicko!
Report Abuse
HatLicense is not online. HatLicense
Joined: 16 Mar 2015
Total Posts: 330
18 Jul 2016 07:11 PM
What is this for?

if path ~= {} then
if pcall(function() npc.Humanoid:MoveTo(path[2]) end) then
elseif pcall(function() npc.Humanoid:MoveTo(path[1]) end)then


Report Abuse
HatLicense is not online. HatLicense
Joined: 16 Mar 2015
Total Posts: 330
18 Jul 2016 07:12 PM
It works it's just it's not pathfindig.. the player is walking to the last finish without avoiding obstacles
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image