-
What do you want to achieve? I’m making my tower defense game and i used Bezier path module script so enemies can walk in corners in Bezier curve
-
What is the issue? It works but not really, at the first waypoint it doesn’t work but it does at the same time i guess? but at the second and others next it does, and the MovingTo is being calculated wrong which makes the tower’s targeting really bad, it aims at the last enemy instead of the first, it’s my first time doing something like this.
-
What solutions have you tried so far? I know how people used this but I’m really bad at calculation
Enemy Moving Function
function enemy.Move(enemy, map, movingToValue)
local humanoid = enemy:WaitForChild("Humanoid")
local waypoints = map.Waypoints
local Positions = {}
for _, waypoint in ipairs(waypoints:GetChildren()) do
table.insert(Positions, waypoint.Position)
end
local NewPath = BezierPath.new(Positions, 3)
if movingToValue == nil then
for t = 0, 1, 1/100 do
enemy.Config.MovingTo.Value = math.floor(t * #Positions) + 1
repeat
humanoid:MoveTo(NewPath:CalculateUniformPosition(t))
until humanoid.MoveToFinished:Wait()
end
enemy:Destroy()
if enemy.Name ~= "Arrow" then
map.Base.Humanoid:TakeDamage(humanoid.Health)
TakeDamageEvent:FireAllClients()
end
else
for t = (movingToValue - 1)/#Positions, 1, 1/100 do
enemy.Config.MovingTo.Value = math.floor(t * #Positions) + 1
repeat
humanoid:MoveTo(NewPath:CalculateUniformPosition(t))
until humanoid.MoveToFinished:Wait()
end
enemy:Destroy()
if enemy.Name ~= "Arrow" then
map.Base.Humanoid:TakeDamage(humanoid.Health)
TakeDamageEvent:FireAllClients()
end
end
end
BezierPath Module: