|
| 28 Feb 2015 02:31 AM |
I've tried everything. But for some reason pathfinding just isn't working for me.
This is the script I'm using in my ai. Humanoid is named 'Zombie'.
This script will work in studio sometimes and then stops working. It's like it works then stops then starts back up. Online it barely works at all. The ai's just stop moving after a while. What am I doing wrong?
I lowered the emptycutoff, but still they don't work right?
game:GetService("PathfindingService").EmptyCutoff = 0.01
local sp = script.Parent
debouncer = false local humanoid = sp:WaitForChild("Zombie")
local p=game:GetService("PathfindingService")
function findNearestTorso(pos) local list = game.Players:GetChildren() local torso = nil local dist = 10000000 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2:IsA("Player")) then if temp2.Character:findFirstChild("Humanoid") == nil then return end if temp2.Character:findFirstChild("Torso") == nil then return end temp = temp2.Character:findFirstChild("Torso") human = temp2.Character:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end
function setPATH()
local target=findNearestTorso(script.Parent.Torso.Position) if target~=nil then local path=p:ComputeRawPathAsync(script.Parent.Torso.Position,target.Position,500) if path.Status==Enum.PathStatus.Success then local points=path:GetPointCoordinates() for _,v in pairs(points) do local setback=0 repeat wait() if setback==10 then break end setback=setback+1 script.Parent.Zombie:MoveTo(v) until (script.Parent.Torso.Position-v).magnitude<3 wait() end else end end wait() setPATH() end setPATH() |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 28 Feb 2015 02:38 AM |
else end
._.
I gave up. It has nothing to do with your script but I wanted you to know why I think this problem is entirely on your bad scripting. |
|
|
| Report Abuse |
|
|
|
| 28 Feb 2015 02:41 AM |
I had a print command there that I removed jeez. But that's not an answer, can anyone help me?
I swear that pathfinding has been broken in updates. Because I had the exact same script work perfectly a few months ago, and in the last 4 weeks or so I've noticed it doesn't work properly. |
|
|
| Report Abuse |
|
|
LucasLua
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 7386 |
|
|
| 28 Feb 2015 03:17 AM |
repeat wait() if setback==10 then break end setback=setback+1 script.Parent.Zombie:MoveTo(v) until (script.Parent.Torso.Position-v).magnitude<3
This is the only thing that would cause you problems.
The problem is that if the point is in the correct position but close to the floor the Torso could be right on top of it but still be higher than 3 studs above it. |
|
|
| Report Abuse |
|
|
|
| 28 Feb 2015 12:21 PM |
Ok, well I changed it out if that was the problem. But I don't think that was the problem. The points land on the surface whatever surface the ai can walk on so it wouldn't make points higher and lower than others unless it could jump.
But anyways, I did this. It seems to be working just like the one I had was, but the movement is so choppy. The humanoid walks to each point and stops and starts again for like 1/3 a second. What can I do to change this?
repeat wait() if setback==10 then break end setback=setback+1 script.Parent.Zombie:MoveTo(v) until script.Parent.Torso.Position.Y == v.Y) |
|
|
| Report Abuse |
|
|
|
| 28 Feb 2015 12:31 PM |
| nvm, I divided the points in the for loop, and then multiplied them. Seems to be working okay now. |
|
|
| Report Abuse |
|
|