So basically I’m working on a tower defense game. And I’m using pathfinding to make my enemies walk to the end using the path. But I noticed that when a zombie is too slow they tend to move to the next point earlier / take shortcuts. Is there any way I can prevent this from happening?
local PathfindingService = game:GetService("PathfindingService")
local animTrack = script.Parent.Humanoid:LoadAnimation(game.Workspace.DeathWalk)
animTrack.Looped = true
animTrack:Play()
local zombie = script.Parent
local humanoid = zombie.Humanoid
spawn(function()
for _,waypoints in pairs(game.Workspace.Waypoints:GetChildren()) do
local path = PathfindingService:CreatePath()
path:ComputeAsync(zombie.HumanoidRootPart.Position, waypoints.Position)
local wp = path:GetWaypoints()
for _, wp in pairs(wp) do
humanoid:MoveTo(wp.Position)
humanoid.MoveToFinished:Wait()
end
end
end)
local PathfindingService = game:GetService("PathfindingService")
local animTrack = script.Parent.Humanoid:LoadAnimation(game.Workspace.DeathWalk)
animTrack.Looped = true
animTrack:Play()
local zombie = script.Parent
local humanoid = zombie.Humanoid
spawn(function()
for _,waypoints in pairs(game.Workspace.Waypoints:GetChildren()) do
local path = PathfindingService:CreatePath()
path:ComputeAsync(zombie.HumanoidRootPart.Position, waypoints.Position)
local wp = path:GetWaypoints()
for _, wp in pairs(wp) do
repeat
humanoid:MoveTo(wp.Position)
wait(.1)
until humanoid.MoveToFinished:Wait()
end
end
end)
So i changed it to this but now he doesn’t even move. The animation still plays though.
It looks that you already created the waypoints in game.Workspace.Waypoints and in that case, you should not need to use pathfinding service. So something like this:
for _,waypoint in pairs(workspace.Waypoints:GetChildren()) do -- You can use workspace instead of game.Workspace
repeat
humanoid:MoveTo(waypoint.Position)
-- I don't think that you need the wait here
until humanoid.MoveToFinished:Wait()
end