-
Hello, currently I’m trying to create a game in a Tower Defense genre and the only problem is Enemy / Units System. I want to make a good Enemy / Units System which can hold really much objects (enemies and units) and make their movement very smooth on the client and it should always be in the same position on the server, so basically there shouldn’t be any desynchronization.
-
Main issue is that roblox moving methods i tried didn’t give me a perfect result I want, there always was a little but meaningful problem.
-
I have tried very much solutions: Humanoid and Pathfinding uncluding :SetNetworkOwner(), TweenService, RunService, BodyMovers, Much math with while lua cycle, etc, every possible method in my mind.
MORE ABOUT METHODS & PROBLEMS:
1. Humanoid and Pathfinding uncluding :SetNetworkOwner().
Basically Humanoid is the worst way to make this system, because it’s moving method Humanoid:MoveTo() is really bad and laggy. Also when enemy is little and it reaches the target, there is problem like “sliding”, the model simply slides past the desired point. And Roblox Pathfinding is a hard headache, so it’s really very bad decision to use it in my system. Also :SetNetworkOwner() doesn’t really reduce lags and help in total, also as you may understand there was anchored parts in absolutely every version of Enemies System, so :SetNetworkOwner() it probably useless.
2. TweenService.
So the TweenService is a good decision at first sight, but when you try to use it, it becomes a headache. I tried very much variants of System, like moving Enemy on both game sides, so the client moves the enemy separately from the server, Moving Enemy only on the Server/Client, but in Server case it’s replicating not smoothly (the client is bad for obvious reasons).
So what was the problem? An amount of enemies it can hold (I haven’t mentioned the huge number of re-creations of the tween due to the change in the speed of the enemy). 100 Created objects already kill game, it’s moving becomes really bad and they start to teleport.
3. RunService.
So the RunService was one the best decisions i tried, using it i made a system which works separately on the server and client. It was able to move very smooth and without lag and teleports up to 1 thousand of enemies, and i thought that i found the solution, but I was wrong. As you know (I hope you know), RunService is based on your FPS, so .Heartbeat or .RenderStepped Events speed depends on your FPS, that’s caused a new problem, enemies was desynchronized among clients with different FPS, I tried to add more math to calculations so including player FPS could give you the same result on all devices, but it didn’t really help. Also there was a desynchronization event between client with good FPS and server. Once client lagged a bit, enemies was desynchronized forever.
I found a GIF with this system (for nerds: models are mine and they wasn’t stolen from known TD game, i made them for a testings.):
4. BodyMovers.
So in short, Body movers are also make lags and desynchronization when enemies amount getting up to 100. Also they can’t have a constant speed.
5. Much math with while lua cycle.
This method is really bad because moving is not smooth. Also it’s fairly laggy when there is like 500 Enemies Objects.
MORE INFO & MY OPINION:
All numbers are results of tests, so it is not just approximate value. Every method causes a lag when there is a lot of Enemies (especially when we are talking about 1-2k enemies or units objects) and it’s pretty predictable, because everyone’s PC has different power, but I’am talking about client lags, it appears when such amount of Enemies or Units are spawned. So client is getting slowed, that’s also can call a desynchronization between Client and Server, so I thought that we can make this Enemies/Units System on the Server, but there is no way to make it with smoothly moving, so that’s why we have to replicate system on the Client and on the Server separately.
So I really want to ask you, how theoretically I can script this System, which methods I should use to get best optimization and make smooth movement without desynchronization. I really appreciate all answers, thank you for reading my problem and for your answers!
P.S.: Sorry for grammar mistakes, English isn’t my best.