Help with Tower Defense Game Migrating from MoveTo to nodes and position syncing

Lerp actually just eases the position when it’s close to the end or just started, think of using Quad or something similar in TweenService EasingStyle and using EasingDirection InOut.

Easing Styles for TweenService.

An easy way to just simplify it is to just do a linear step using TweenService. This is exactly how I did it above. Here is the code to change it.

local movement = game:GetService("TweenService"):Create(ClientModel.PrimaryPart, TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {CFrame = workspace.Nodes[EnemyInfo.Node + 1].CFrame})
movement:Play()

well sure but i cant use tween service on newEnemy since its literally just a table. remember im using pure data on the server

Alright, I fixed it (I think). The first one should be the part you were lerping before.

I don’t think its working per say. I tried this and it doesn’t seem to work at all.

connection = game:GetService("RunService").Heartbeat:Connect(function(delta)
			if EnemyInfo.Node >= #workspace.Nodes:GetChildren() or not workspace.Nodes[EnemyInfo.Node + 1] then
				warn("movement completed")
				connection:Disconnect()
				return
			end

			local Cframe: CFrame = ClientModel.PrimaryPart.CFrame
			local distance: number = (Cframe.Position - workspace.Nodes[EnemyInfo.Node + 1].Position).Magnitude
			local duration = (distance / EnemyInfo.Speed) * 25
			local lerpedCFrame = Cframe:Lerp(workspace.Nodes[EnemyInfo.Node + 1].CFrame, alpha)
			--ClientModel.PrimaryPart.CFrame = lerpedCFrame
			local movement = game:GetService("TweenService"):Create(ClientModel.PrimaryPart, TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {CFrame = workspace.Nodes[EnemyInfo.Node + 1].CFrame})
			movement:Play()
			alpha += delta / duration
			if alpha >= 1 then
				EnemyInfo.Node += 1
				alpha = 0
			end
		end)

would you mind adding me so i can invite you to edit the file and test it with me?

Sure! I just added you.

Limit yes

I added you to the file its called EnemyV2 Test, we can chat directly in the roblox chat there

I have figured out the issue and fixed all the problems with the system, special thanks to @redpepperdoc2006 for the help!

1 Like

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