Server/Client entity replication for TD game

These days I was trying to create a server-client entity system for my TD game. I used BezierPath, an easy to use and optimized spline path module for TD games and general paths
module to create the movement of my entities, but after some time I observer that is very problematic to create some effects like stun, slow, knockback.

(I was strying to change the start time, but it’s awful…)

I’d like if someone can give me some advices how can I implement this movement of entities, I have table with entities on server side, and also I create one on client, where I kepp info like position, hp, id, model etc.

Also it’s very important to allow entites to move circle-like, not only straight lines.

for id, entitySaved in pairs(SavedEntities) do
		if entitySaved.Speed ~= 0 then
			local elapsedTime = workspace:GetServerTimeNow() - tonumber(entitySaved.StartTime)
			local progress = elapsedTime / (Length / tonumber(entitySaved.Speed))
			local newCframe = newPath:CalculateUniformCFrame(progress)

			entitySaved["Model"]:PivotTo(newCframe)
			entitySaved.OldStartTime = entitySaved.StartTime
			entitySaved.Progress = progress
		else
			if entitySaved.StartTime ~= entitySaved.OldStartTime then
				entitySaved.OldStartTime = entitySaved.StartTime
				
				local elapsedTime = workspace:GetServerTimeNow() - tonumber(entitySaved.StartTime)
				local progress = elapsedTime / (Length / tonumber(entitySaved.OrigSpeed))
				local newCframe = newPath:CalculateUniformCFrame(progress)

				entitySaved["Model"]:PivotTo(newCframe)
				entitySaved.OldStartTime = entitySaved.StartTime
				entitySaved.Progress = progress
			else
				local oldNewCframe = newPath:CalculateUniformCFrame(entitySaved.Progress)

				entitySaved["Model"]:PivotTo(oldNewCframe)
			end
		end
	end

I was check this on the server every hearbeat.

1 Like

BezierPath is fine, as long as it’s being done in the client.

1 Like

Why on client? I need to create a movement on the server and replicate it to the client. If this module is ok, the I need to solve the problem, if the speed is 0 then the progress is also 0, or if speed is bigger and original one then entity is teleporting… (I’m trying to implement effects like stun, slow, acceleration, knockback, teleport)

1 Like

I guess it’s because you can calculate the time that it takes to reach the end and track it that way, and then do the visual stuff like the Bezier on the client. If they get stunned or whatever, you could manipulate the speed of the movement, and add more time on the server.

That way, you’re saving server memory for other stuff and allocating client memory for visual stuff.

I was tried like that, I added time for startTime attribute, but if stun and teleport for example is applied a almost same time, then it has some wrong positions, after it come back to normal.

May be I can in other way to calculate the T variable for :CalculateUniformCFrame(), but idk how…

Yeah that can be an issue. Perhaps you could sync the movement based on a 0 to 1 scale of the path length? Then you could check if the runner is within the margin of error. Just some ideas, otherwise I have no clue.