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
 

Re: PathfindingService?

Previous Thread :: Next Thread 
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
10 Feb 2017 02:16 AM
How do I actually get the calculated path? The script I wrote only seems to make the NPC follow me directly (without avoiding obstacles). What am I doing wrong?


local path = game:GetService("PathfindingService"):ComputeSmoothPathAsync(script.Parent.Parent.HumanoidRootPart.Position,game.Workspace.Player1.HumanoidRootPart.Position,200)
local p = path:GetPointCoordinates()


--//

Thanks.


~MightyDantheman~
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
10 Feb 2017 02:16 AM
Sorry, I didn't copy the whole script.


game.Workspace:WaitForChild("Player1"):WaitForChild("HumanoidRootPart")
script.Parent.Parent:WaitForChild("HumanoidRootPart")
while true do
local path = game:GetService("PathfindingService"):ComputeSmoothPathAsync(script.Parent.Parent.HumanoidRootPart.Position,game.Workspace.Player1.HumanoidRootPart.Position,200)
p = path:GetPointCoordinates()
for x=1,#p do
script.Parent.WalkToPoint = p[x]
end
wait()
end


--//


~MightyDantheman~
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
10 Feb 2017 02:17 AM
haven't used it myself

local path = game:GetService("PathfindingService"):ComputeSmoothPathAsync(script.Parent.Parent.HumanoidRootPart.Position,game.Workspace.Player1.HumanoidRootPart.Position,200)
local p = path:GetPointCoordinates()

for i, v in pairs(p) do
script.Parent.Parent.Humanoid:MoveTo(v)
repeat wait() until (script.Parent.Parent.HumanoidRootPart.Position - v).magnitude < 3.5
end


Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
10 Feb 2017 02:20 AM
The NPC moved for just a second then stopped.


~MightyDantheman~
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
10 Feb 2017 02:25 AM
local path = game:GetService("PathfindingService"):ComputeSmoothPathAsync(script.Parent.Parent.HumanoidRootPart.Position,game.Workspace.Player1.HumanoidRootPart.Position,200)
local p = path:GetPointCoordinates()

for i, v in pairs(p) do
script.Parent.Parent.Humanoid:MoveTo(v)
repeat script.Parent.Parent.Humanoid:MoveTo(v) wait(.1) until (script.Parent.Parent.HumanoidRootPart.Position - v).magnitude < 3.5
end

idk


Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
10 Feb 2017 02:37 AM
That also didn't really do anything. The ROBLOX tutorial made things looks simple. -.-

Video:
https://youtu.be/pQ9Mcc-5UuA


~MightyDantheman~
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
10 Feb 2017 02:55 AM
Well, I'll ask again tomorrow. I can't figure this thing out. I don't think I'm doing anything different from the video besides using a Humanoid instead of a path of parts.


~MightyDantheman~
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
10 Feb 2017 09:42 AM
it's rather simple really, are you making an NPC follow you or what exactly do you want it for?
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
10 Feb 2017 09:48 AM
while wait() do
pfs = game:GetService("PathfindingService")
path = pfs:ComputeRawPathAsync(script.Parent.Torso.Position,workspace.DESTINATION.Position,500)

points = path:GetPointCoordinates()

for _,v in pairs(points) do
local humanoid = script.Parent:FindFirstChild("Humanoid")
humanoid:MoveTo(v)
end
end

---just an example
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
10 Feb 2017 09:54 AM
the reason your script didn't work is because it's not looped so it would only go through the points once, disregarding any updated points
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
10 Feb 2017 09:54 AM
there's also a way to check if the path worked or not
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
10 Feb 2017 11:04 AM
I'm trying to make ## ## follow me, but avoid obstacles. Your script is about the same is the one I wrote in Studio, but it still doesn't work. ~MightyDantheman~
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
10 Feb 2017 11:04 AM
is your game FE? mine worked fine
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
10 Feb 2017 11:10 AM
I don't think FE would have any affect on this. The NPC follows me, but doesn't avoid obstacles. Here's my script:


script.Parent.Parent:WaitForChild("HumanoidRootPart")
game.Workspace:WaitForChild("Player1"):WaitForChild("HumanoidRootPart")
while true do
local p = game:GetService("PathfindingService"):ComputeSmoothPathAsync(script.Parent.Parent.HumanoidRootPart.Position,game.Workspace.Player1.HumanoidRootPart.Position,500):GetPointCoordinates()
for _,v in pairs(p) do
script.Parent:MoveTo(v)
end
wait()
end


--//


~MightyDantheman~
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
10 Feb 2017 11:13 AM
it should avoid obstacles between the start and end of the path, im not sure
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
10 Feb 2017 11:14 AM
This actually seems to work, but the NPC walks around kinda buggy:


script.Parent.Parent:WaitForChild("HumanoidRootPart")
game.Workspace:WaitForChild("Player1"):WaitForChild("HumanoidRootPart")
while true do
local p = game:GetService("PathfindingService"):ComputeSmoothPathAsync(script.Parent.Parent.HumanoidRootPart.Position,game.Workspace.Player1.HumanoidRootPart.Position,500):GetPointCoordinates()
for _,v in pairs(p) do
script.Parent:MoveTo(v)
repeat wait() until (script.Parent.Parent.HumanoidRootPart.Position-game.Workspace.Player1.HumanoidRootPart.Position).magnitude > 3
end
wait()
end


--//


~MightyDantheman~
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
10 Feb 2017 11:14 AM
try ##### ## #### two parts for a quick test and you'll see that the path alters when you move a part in-between the start and the end
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
10 Feb 2017 11:17 AM
I have one obstacle. The NPC is not only moving in a very strange way, it only avoids obstacles half the time. It doesn't give itself enough room to actually walk around it.


~MightyDantheman~
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
10 Feb 2017 11:18 AM
If it makes any difference, I'm using a copy of myself (from test mode) as the NPC.


~MightyDantheman~
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
10 Feb 2017 11:19 AM
try using ComputeSmoothPathAsync
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
10 Feb 2017 11:19 AM
wait nvm didn't realize, mb
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
10 Feb 2017 11:20 AM
check the path's status maybe?
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
10 Feb 2017 11:26 AM
It says success, but it's still acting very strangely.


~MightyDantheman~
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
10 Feb 2017 11:29 AM
Here's the thing. It's zigzagging randomly and it keeps getting stuck on corners. Is there a way to get it to widen then path?


~MightyDantheman~
Report Abuse
XCVlll is not online. XCVlll
Joined: 23 Oct 2008
Total Posts: 963
10 Feb 2017 11:31 AM
it shouldn't do that, im not too sure why it does
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