Hello everybody!
I’m once again asking you guys for help with :MoveTo()
.
So, in my tower defense game, zombies spawn at the start of the map and make their way to the end by walking from a waypoint to another.
Except the fact that some zombies do that, while other get stuck.
The issue:
Some of the zombies can walk between waypoints and get to the end, but bigger enemies (bosses, mini-bosses) tend to get stuck at the first one. Here’s a video showing the problem:
The code I used:
This is the code that is responsible for the pathfinding (every zombie’s movement is controlled by a main script)
for _, waypoints in pairs(script.Parent.Waypoints:GetChildren()) do
local successStatus = false
local function timeoutUpdater()
spawn(function()
wait(7.8)
if successStatus == false then
if zombie:FindFirstChild("Humanoid") then
zombie.Humanoid:MoveTo(waypoints.Position)
timeoutUpdater()
end
end
end)
end
timeoutUpdater()
zombie.Humanoid:MoveTo(waypoints.Position)
zombie.Humanoid.MoveToFinished:Wait()
successStatus = true
end
The solutions I tried:
For now, I only tried changing the :MoveTo()
position from waypoints.Position
to a Vector3.new
having as parameters waypoints.Position.X, zombie.HumanoidRootPart.Position.Y, waypoints.Position.z
. Example in the code:
for _, waypoints in pairs(script.Parent.Waypoints:GetChildren()) do
local successStatus = false
local moveToPos = Vector3.new(waypoints.Position.X, zombie.HumanoidRootPart.Position.Y, waypoints.Position.z)
local function timeoutUpdater()
spawn(function()
wait(7.8)
if successStatus == false then
if zombie:FindFirstChild("Humanoid") then
zombie.Humanoid:MoveTo(moveToPos)
timeoutUpdater()
end
end
end)
end
timeoutUpdater()
zombie.Humanoid:MoveTo(moveToPos)
zombie.Humanoid.MoveToFinished:Wait()
successStatus = true
end
Other notes:
I don’t really know much about making humanoids move / pathfinding so sorry if it’s something really obvious.
Edit: Forgot to mention, CanCollide is off for al the waypoints, but it should be obvious as the smaller zombies go through them.