What do you want to achieve? I want to fix a bug in my tower defense game involving the enemies.
What is the issue?
I made it so the humanoid moves to a certain point so the enemies can move along the path. The problem is that they stop at each point for half a second before moving again and it looks like they’re stuttering.
(The reason there are so many is because using MoveTo has a max of 8 seconds and my slow boss freezes if it doesn’t walk to another point.
What solutions have you tried so far? I’ve tried reviewing the scripts to see if there are any wait times that are too long causing them to stutter, which didn’t work.
local hum = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
local nodes = game.Workspace.Path1:GetChildren()
table.sort(nodes, function(nodeA, nodeB)
local nodeNumberA = string.match(nodeA.Name, "%d+")
local nodeNumberB = string.match(nodeB.Name, "%d+")
return tonumber(nodeNumberA) < tonumber(nodeNumberB)
end)
for _, node in ipairs(nodes) do
hum:MoveTo(node.Position)
local distance = (torso.Position - node.Position).Magnitude
wait (distance / hum.WalkSpeed)
end
Switch the goal a frame or so before they reach the goal. You might be able to use this control module which has a tested termination condition. I am also working on a more advanced pathfinder which will be building onto this controller, you can follow the progress or send feature requests here: Polaris-Nav
Unfortunately that method even fails to return sometimes… It is a very common issue developers have with the pathfinder, and why many alternatives have been made.
local hum = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
local nodes = game.Workspace.Path1:GetChildren()
local targetReached = false
local function moveTo(targetPoint)
targetReached = false
local connection
connection = hum.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
end)
-- start walking
hum:MoveTo(targetPoint)
end
for _, node in ipairs(nodes) do
moveTo(node.Position)
repeat
wait()
until targetReached
end