Tower defence enemies lagging behind

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.

Alright, I already had support for that, but it does come at a slight overhead. Shouldn’t be too significant though.

Hm, can you use the newly released BezierPath? A new version was released 8 hours ago.

This was happening when we were using tweens

You do realize that says “Remove curve clamp” right? Not just “Remove curve”? I’m assuming that’s what you mean anyways.

Edit: I just realized what you meant, try my edited server code and it should work.

The offset was added incorrectly, because it wouldn’t take into account the current direction.
I’ve also increased the refresh_rate, so it uses less resources to calculate the track. If that doesn’t perform accurately, change it back to 0.2.

Is it just the formula? because i modified your code, to take into account the waypoint folder, because i started on tower targeting. Can you highlight what you changed?

I changed 0.2 to 0.5 (switch this back to 0.2 if it isn’t accurate enough for your liking):

I added the offset via CFrame so it takes orientation into account:

By the way, make sure you reference the CFrame attribute in each model for this.

You may also find this useful:

1 Like

I actually turned the refresh rate down to 0.1, because the enemies were shaking.(they were pausing then moving) I think its good though. Thank you!

1 Like

Sorry for all the inconveniences along the way lol, I’ve learnt a lot helping you so far.

Goodluck on your tower defense!

1 Like

you know, me and my friend experimenting now, because i’m only for math, but from my perspective, 200 enemies on scene is max, you could make some enemies bigger and more HP, maybe some type of damage protection (explosion proof, magic proof, bullet proof, laser proof ect.) soo player will have illusion of strong enemy, then player will keen on it, instead of a lot of them, this will make interactions better overall, because you’ll try to destroy 5 enemies, rest will be only a support for them.

2 Likes

I’ve also realized that there was another optimization I could’ve done, which I implemented in my edited client code.

All I did was switch table.insert to directly setting the value in the table, which is 2x faster in my testing.

2 Likes

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