Tower defence enemies lagging behind

Okay, I narrowed the lag down to the enemies loading. With r6 enemies, it can handle thousands of enemies at once. Also, when there are a lot of enemies, they start glitching around. Same if I change the speed.

Try my edited client code. I clamped the deltaTime.

1 Like

they still glitch around when i change the speed. When i change the speed, they just glitched off the map and damaged my base.

Like as in they go backwards or something? I donā€™t get what you mean by glitching.

like they just fly around, then go back to the track.

Sorry for asking to send so many videos, but could you send a video of what it looks like?

You havenā€™t changed the refresh_rate and deltaTime multipliers right?

Also:

1 Like

Here you go!

Yep, I am using the latest version

1 Like

My formula for distance was wrong, try my edited server and client code.

Yep, it works pretty well now. It still is a bit laggy tho. How could i optimize it more? Should i use actors?

You could try to use Actors but first off, you can try to create the objects only on the client, which should help with performance. It would also allow for streaming enabled to be turned on, further increasing performance.

Iā€™ll try to implement this, wait like 5 minutes.

Finished implementing the above, try my edited server and client code. Iā€™ve also implemented BulkMoveTo.

There is a crucial thing you have to do though, and itā€™s moving the ServerStorage.Enemies folder to ReplicatedStorage.Enemies. (AND IF POSSIBLE, re-enable StreamingEnabled)

To know that itā€™s working, it should look the exact same on the client, but on the server, you should not see anything.

Also, just asking because I may be able to do more optimizations, do you plan on switching the map in the middle of the game? And if you do switch the map in the middle of the game, are you destroying the old one?

It works pretty well, but the loading is still really laggy.

Could you answer the questions I posted? Is it also working better than before (specifically the loading)?

Could you read through my reply and make sure you did everything like turning on StreamingEnabled?

Also, thereā€™s a point where no matter how many optimizations we do, it wonā€™t be better. Like for example, if there are 2000 enemies, then obviously if your hardware isnā€™t good enough, thereā€™s no way to make it run smoothly.

1 Like

Sorry for the late response. Yeah, streaming enabled triggers the cut corner glitch, so that kinda sucks. One thing I noticed though is that the X axis offset only works sometimes. How can I fix that?
@Katrist

Ok soo iā€™m working on similar system, and me and my friend used linear interpolation and some replication, we have enemies as module script with pure math and variables that lerp to points. Then we replicate position to client where animations and effects are done, itā€™s hard but it donā€™t lag much

Turn StreamingEnabled back off and tell me the answers to these

Another video would also help.

This is pretty much the same way Iā€™m implementing it. How much enemies are possible with your system? Iā€™m pretty sure the goal is for at least 500 enemies to run smoothly.

1 Like

Also, for your spawnenemies function, get rid of the coroutine, we already have one in the function itā€™s calling so it isnā€™t needed.

Your current code:

		local spawnthread = coroutine.create(function()
			enemy.spawn(name, nodes, exit, enemyspawn.CFrame)
		end)
		coroutine.resume(spawnthread)
		task.wait(math.random(0.2, 0.3))

Fixed:

enemy.spawn(name, nodes, exit, enemyspawn.CFrame)
task.wait(math.random(0.2, 0.3))

Actually, they work pretty well with 1000 enemies, after i switched the rig type to r6.

1 Like

like I might be doing that at some point, but not now. It would be nice for backward support though.

Heres a video:

You can see the X axis offset only work sometimes.