Tower Defense Move System with Tween Service

  • I want to make a move system for the enemies. In this case, the enemies in my game is called “Blocks”. Since they are parts, I thought that I can use TweenService to make the move system for them.

  • This the code I wrote:

	local Waypoints = map:FindFirstChild("Waypoints")
	local BlockStats = block:FindFirstChild("Stats")
	
	local Speed = BlockStats.Speed.Value
		
	for waypoint = 1, #Waypoints:GetChildren() do
		local MoveAnimation = TweenService:Create(block, TweenInfo.new(Speed, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Position = Waypoints[waypoint].Position})

		MoveAnimation:Play()
		MoveAnimation.Completed:Wait()
	end
end

The issue is, when the part is longer, it moves faster; when the part is shorter, it moves slower.

image

So, how can I fix this problem. Or, is TweenService is even a good idea to use?

Thank you

make it a humanoid based character and use :moveto

since you already have the points needed you can use Humanoid:MoveTo(Position) to move it, the walkspeed of the humanoid will determine how fast it moves

if you really want to use tweens then you will have to use some math to get the time it will take to get to point B from point A

time = distance / speed

1 Like

Thanks and I guess I will try the tween service first. This is because everytime I make a tower defense game I always use the humanoid:MoveTo() function. I want to try new thing.

But if it doesn’t work, I will use the humanoid method.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.