#Tower Defense Enemy Movement System Glitchy
22 messages · Page 1 of 1 (latest)
here's how they start
here's how they look after they crossed several nodes
their distance between each other seems to break each time they turn
Well, you get the idea.
Essentially, here's the code for moving them:
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
for _, npc in ipairs(game.Workspace.TowerDefense.Test.Mobs:GetChildren()) do
local distance = (game.Workspace.TowerDefense.Test.Path[npc.Settings.GoalNode.Value].Position - npc:GetPivot().Position).Magnitude
if distance < 0.5 then -- original 0.5
if npc.Settings.GoalNode.Value ~= #game.Workspace.TowerDefense.Test.Path:GetChildren() then
npc.Settings.CurrentNode.Value = npc.Settings.CurrentNode.Value + 1
npc.Settings.GoalNode.Value = npc.Settings.GoalNode.Value + 1
npc_library.Rotate(npc)
npc:PivotTo(CFrame.new(game.Workspace.TowerDefense.Test.Path[npc.Settings.CurrentNode.Value].Position, game.Workspace.TowerDefense.Test.Path[npc.Settings.GoalNode.Value].Position))
else
print("DONE!")
npc:Destroy()
end
else
npc:PivotTo(npc:GetPivot() + npc:GetPivot().LookVector * 20 * deltaTime) -- original 20
end
end
end)
What I'm trying to achieve is to space them all out evenly exactly how they spawn
but some reason they end up catching up to each other although they are all at the same speed
still need help
still need help
still need help
still need help
can't understand a single block of code, simplify this up.
local Mobs = game.Workspace.TowerDefense.Test
local Path = game.Workspace.TowerDefense.Test.Path
game:GetService("RunService").Heartbeat:Connect(function(dt)
for _, npc in ipairs(Mobs:GetChildren()) do
local Set = npc.Settings
local CurrentNode, GoalNode = Set.CurrentNode, Set.CurrentNode
local distance = (Path[GoalNode.Value].Position - npc:GetPivot().Position).Magnitude
if distance < 0.5 then
if GoalNode.Value ~= #Path:GetChildren() then
CurrentNode.Value += 1
GoalNode.Value += 1
npc_library.Rotate(npc)
npc:PivotTo(CFrame.new(Path[CurrentNode.Value].Position, Path[GoalNode.Value].Position))
else
print("DONE!")
npc:Destroy()
end
else
npc:PivotTo(npc:GetPivot() + npc:GetPivot().LookVector * 20 * dt) -- original 20
end
end
end)
simplified enough?
The issue is the server ping
You need to optimize it so that it can run smoothly on the server
Or could be something that is blocking the path
and then delay it
My thought on this is the server ping, happens to me alot too.
alright ill look into it