|
| 02 Aug 2014 11:00 AM |
--Pathfinding local zombie = script.Parent local PointModel = Instance.new('Model', Workspace) PointModel.Name = 'Points'
function ReDrawPath() while wait(0.001) do path = game:GetService('PathfindingService'):ComputeRawPathAsync(zombie.Torso.Position, zombie.Humanoid.WalkToPart.Position, 500) points = path:GetPointCoordinates() PointModel:ClearAllChildren() for i = 1, #points do p = Instance.new('Part', PointModel) p.Position = points[i] p.Anchored = true p.CanCollide = false p.Size = Vector3.new(1, 1, 1) zombie.Humanoid:MoveTo(points[i]) end if zombie.Humanoid.WalkToPart.Parent == nil then break end end end
zombie.Humanoid.Changed:connect(ReDrawPath)
--TargetPicking local zombie = script.Parent local searching = false local following = nil
game.Players.PlayerAdded:connect(function(plr) plr.CharacterAdded:connect(function(char) if not searching then searching = true following = char repeat wait() zombie.Humanoid:MoveTo(char.Torso.Position, char.Torso) until searching == false or following == nil end char.Humanoid.Died:connect(function() if char == following then searching = false following = nil zombie.Humanoid:MoveTo(0, 0, 0) end end) end) end)
I really need it! I think that people were right, the Pathfinding Script makes all the Lag, but, wat I forgot about the Pathfinding Script was that it depends if it has a Target or not, so wenever it gets a New Target, it Starts making a Path... so I'd like to know, wat can I do to Compact these Scripts and make them Better??? |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 11:01 AM |
| Jammer is on the case. A couple of moments pl0x. |
|
|
| Report Abuse |
|
|
|
| 02 Aug 2014 11:02 AM |
| thnx, hardly anyone even answers my Threads these days :/ |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 11:17 AM |
Did what I could. Lemme know what you think and if anything's broken, I didn't test it personally, just used Notepad++. If everything goes accordingly, then it should work a little better for you too. The 'lag' problem isn't from the pathfinding - Roblox has that pretty well done. The Humanoid.Changed event goes off any time the Torso of the same model changes in the slightest - Any time it moves, changes velocity, color, anything, not just went the Humanoid itself changes. Have a script.
Zombie = script.Parent function DrawPath(TargetPoint) Path = game:GetService("PathfindingService"):ComputeRawPathAsync(Zombie.Torso.Position, TargetPoint, 512) if Path.Status == Enum.PathStatus.Success then Path = Path:GetPointCoordinates() else Path = nil end return Path end Target = nil game:GetService("Players").PlayerAdded:connect(function(Player) Player.CharacterAdded:connect(function(Character) if not Target then Target = Character.Humanoid while Target and Target.Parent and Target.Health > 0 and Target.Torso and wait() do local Route = DrawPath(Target.Torso.Position) if (Target.Torso.Position - Zombie.Torso.Position).Magnitude > 20 and Route then for X = 1, #Route do local Timer = 10 while Timer > 0 and (Zombie.Torso.Position - Route[X]).Magnitude > 3 and (Target.Torso.Position - Route[#Route]).Magnitude < 15 and (Target.Torso.Position - Zombie.Torso.Position).Magnitude > 20 do Zombie.Humanoid:MoveTo(Route[X]) Timer = Timer - 1 wait(0.1) end end else Zombie.Humanoid:MoveTo(Target.Torso.Position, Target.Torso) end end Target = nil end end) end) |
|
|
| Report Abuse |
|
|
|
| 02 Aug 2014 11:30 AM |
| nice Script, but I read it all and I didnt really see any Errors, but the Zombie doesnt follow me nor are there any Errors shown in the Output :/ |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 11:32 AM |
| I compacted them like you said but I kept the basic functions you left me. You have the zombie select the newest player to join the game if it doesn't already have a target - In other words the zombie needs to be in the game before the player for it to target you, and once you've been put in the game after the zombie, any time your character loads you'll be able to be targeted. Want me to change it or can you handle editing it yourself? |
|
|
| Report Abuse |
|
|
|
| 02 Aug 2014 11:34 AM |
| well if ur not Busy, feel free to do so, but if u dont feel like editing, no worries, I can Edit it, hardly anyone would help me with a thing like this, thnx |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
| |
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 11:40 AM |
Zombie = script.Parent function DrawPath(TargetPoint) Path = game:GetService("PathfindingService"):ComputeRawPathAsync(Zombie.Torso.Position, TargetPoint, 512) if Path.Status == Enum.PathStatus.Success then Path = Path:GetPointCoordinates() else Path = nil end return Path end while wait() do Target, Dist = nil, math.huge while not Target and wait(0.1) do local Players = game.Players:GetPlayers() for X = 1, #Players do if Players[X].Character and Players[X].Character:FindFirstChild("Humanoid") and Players[X].Character.Humanoid.Health > 0 and (Players[X].Character.Torso.Position - Zombie.Torso.Position).Magnitude < Dist then Target, Dist = Players[X].Character.Humanoid, (Players[X].Character.Torso.Position - Zombie.Torso.Position).Magnitude end end end while Target and Target.Parent and Target.Health > 0 and Target.Torso and wait() do local Route = DrawPath(Target.Torso.Position) if (Target.Torso.Position - Zombie.Torso.Position).Magnitude > 20 and Route then for X = 1, #Route do local Timer = 10 while Timer > 0 and (Zombie.Torso.Position - Route[X]).Magnitude > 3 and (Target.Torso.Position - Route[#Route]).Magnitude < 15 and (Target.Torso.Position - Zombie.Torso.Position).Magnitude > 20 do Zombie.Humanoid:MoveTo(Route[X]) Timer = Timer - 1 wait(0.1) end end else Zombie.Humanoid:MoveTo(Target.Torso.Position, Target.Torso) end end end |
|
|
| Report Abuse |
|
|
|
| 02 Aug 2014 11:49 AM |
| I appreciate ur Attempts, but the 1st one had the errors of trying to Acces Path and Route, the 2nd Script u made, the Studio get spretty laggy, and the Zombie still doesn't move :/ |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 11:52 AM |
| I'll test and debug it in studio. |
|
|
| Report Abuse |
|
|
| |
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 11:55 AM |
| The last script I posted is working completely fine and not lagging at all. Make sure it's not an external script that's messing up or causing the lag, I made it as optimal as I can. |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 12:02 PM |
| I'll go over it one more time. I'm actually trying to learn more about pathing while I'm doing this. |
|
|
| Report Abuse |
|
|
|
| 02 Aug 2014 12:08 PM |
| k, cos non of the Zombies seem to go after me :/ try put a Wall between u and the Zombie, to see if it actually works... |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 12:12 PM |
| I might have the distance the zombie stops trying to navigate and starts direct chase too high. |
|
|
| Report Abuse |
|
|
|
| 02 Aug 2014 12:13 PM |
| so he's going straight for u? |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 12:16 PM |
I used a free model map and he navigated up stairs, around and through buildings, and straight for me when there was no path or he was close. I'm almost done debugging it. |
|
|
| Report Abuse |
|
|
| |
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 12:21 PM |
This is as close as I can get it for you right now. The zombie rarely gets stuck when too close to a wall, but the pathing system is completely fine and I even got it to move better diagonally. Enjoy your script and edit it to your liking, I've gotta get to other forums.
Zombie = script.Parent function DrawPath(TargetPoint) Path = game:GetService("PathfindingService"):ComputeRawPathAsync(Zombie.Torso.Position, TargetPoint, 512) if Path.Status == Enum.PathStatus.Success then Path = Path:GetPointCoordinates() local Points = {} local Skip = false for X = 1, #Path do if not Skip and X > 1 and X < #Path and (Path[X].X ~= Path[X - 1].X or Path[X].Z ~= Path[X - 1].Z) and (Path[X].X ~= Path[X + 1].X or Path[X].Z ~= Path[X + 1].Z) then Skip = true table.insert(Points, Path[X]) elseif Skip then Skip = false end end return Points else Path = nil return nil end end while wait() do Target, Dist = nil, math.huge while not Target and wait(0.1) do local Players = game.Players:GetPlayers() for X = 1, #Players do if Players[X].Character and Players[X].Character:FindFirstChild("Humanoid") and Players[X].Character.Humanoid.Health > 0 and (Players[X].Character.Torso.Position - Zombie.Torso.Position).Magnitude < Dist then Target, Dist = Players[X].Character.Humanoid, (Players[X].Character.Torso.Position - Zombie.Torso.Position).Magnitude end end end while Target and Target.Parent and Target.Health > 0 and Target.Torso and wait() do local Route = DrawPath(Target.Torso.Position) if (Target.Torso.Position - Zombie.Torso.Position).Magnitude > 10 and Route then for X = 1, #Route do local Timer = 10 while Timer > 0 and (Zombie.Torso.Position - Route[X]).Magnitude > 3 and (Target.Torso.Position - Route[#Route]).Magnitude < 10 and (Target.Torso.Position - Zombie.Torso.Position).Magnitude > 20 do if Timer == 2 then Zombie.Humanoid.Jump = true end Zombie.Humanoid:MoveTo(Route[X] + (Vector3.new(Route[X].X, 0, Route[X].Z) - Vector3.new(Zombie.Torso.Position.X, 0, Zombie.Torso.Position.Z)).Unit * 2) Timer = Timer - 1 wait(0.1) end end else Zombie.Humanoid:MoveTo(Target.Torso.Position, Target.Torso) end end end |
|
|
| Report Abuse |
|
|
|
| 02 Aug 2014 12:25 PM |
| Thnx, I'll Test it in a few... right now am making a Plugin |
|
|
| Report Abuse |
|
|
|
| 02 Aug 2014 12:28 PM |
You might wanna make it so the zombie has methods you can read instead of just putting the code core like that. Also, you forgot a few locals to things. You also had a delay of 0.01 OMG LAG... 0.38 is perfect for this. You may want to also rethink how the navigating works in these two scripts. If you look in your for loop there is no delay or check if the player gets to the position... and if I am wrong MoveTo() doesn't finish, right? Anyways here is my way of doing this...
local delay = 0.38
local zombie = script.Parent local PointModel = Instance.new('Model', Workspace) PointModel.Name = 'Points'
local newPath = function(object) local path = game:GetService('PathfindingService'):ComputeRawPathAsync(object.Torso.Position, object.Humanoid.WalkToPart.Position, 500) local points = path:GetPointCoordinates() return points end
function ReDrawPath() while wait(delay) do local points = newPath() PointModel:ClearAllChildren() for i, v in pairs(points) do local p = Instance.new('Part', PointModel) p.Position = v p.Anchored = true p.CanCollide = false p.Size = Vector3.new(1, 1, 1) zombie.Humanoid:MoveTo(v) end if zombie.Humanoid.WalkToPart.Parent == nil then break end end end
zombie.Humanoid.Changed:connect(ReDrawPath)
---------------------------------------------------
local delay = 0.38
local zombie = script.Parent local searching = false local following = nil
local Follow = function(char, zombie) searching = not searching following = char repeat wait(delay) zombie.Humanoid:MoveTo(char.Torso.Position, char.Torso) until searching == false or following == nil end
local stopFollowing = function(char) if (char == following) then searching = not searching following = nil zombie.Humanoid:MoveTo(zombie.Position) end end
game.Players.PlayerAdded:connect(function(plr) plr.CharacterAdded:connect(function(char) if not searching then Follow(char) end char.Humanoid.Died:connect(function() stopFollowing(char) end) end) end) |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 12:32 PM |
| Oi. Try my work before criticizing it bb. |
|
|
| Report Abuse |
|
|
|
| 02 Aug 2014 12:33 PM |
| Oi. I wan't talking to you. |
|
|
| Report Abuse |
|
|
Jammer622
|
  |
| Joined: 19 Nov 2008 |
| Total Posts: 1739 |
|
|
| 02 Aug 2014 12:35 PM |
| Oi. Why u posting more work when problem is solved then? wat |
|
|
| Report Abuse |
|
|