Hi, i’m making tower defense game and first time i using lerp inside heartbeat, because it can include enemy’s speed and i can easily stop enemies by setting value to 0 or 1, but then the problem is, is it performant heavy? if for example one script will fire this heartbeat for 300 enemies at once, how can i optimize this? are there any tricks to do that or maybe another way? i tried tweening but it’s laggy too.
i’m sorry if you said so but i couldn’t tell, but what are you using lerp for specifically?
moving enemies, i don’t worried about client, but more about server, on server i move invisible parts when on client animations, model ect.
is your computer not making it so well while this is happening?
you see, i used a very basic test, i made about 200 simulations at the same time, and it lagged
okay, and just double checking, this is all serverside?
yea, moving entities is server side
though it won’t lag the clients, it might make it look a little shaky. try making the script run on any client that can see it. it will be a little more difficult, but it won’t be as hard on the server. while you’re indexing through all the entities in the loop, you could check whether or not it’s nearby when processing its movement. i know that might not work if everything has to be live.
if it’s okay, could i see what you’re doing inside of the .heartbeat? the issue could also be some bad practices in your code too
it’s a test of lerping, it do simple math and then lerp position from Start to finish
i ran a program that runs 200 times per frame and lerps each part back and fourth.
i wasn’t really thinking about the microprofiler, sorry, but it does work pretty well at determining whether or not something is very performance heavy.
local tbl = {}
for i = 1,200 do
local instance = Instance.new("Part",workspace)
instance.Anchored = true
instance.Position = Vector3.new(i*5,1,1)
table.insert(tbl, i, {instance, instance.Position, instance.Position + Vector3.new(0,10,0)})
end
while true do
for i, v in pairs(tbl) do
task.spawn(function()
v[1].Position = v[2]:Lerp(v[3], math.sin(tick()))
end)
end
task.wait()
end
i don’t understand it completely, but the lines reach up to the very top of the frame which means that the frames are taking long to load. you can also hover over each frame and see how bad it is doing.

after testing a few times with the code, i’ve determined that performing the math is most likely the cause for your game running slow. here is the math that is slowing it down in my code:
math.sin(tick())
if i’m assuming your math is more advanced than this, then your CPU is definitely suffering (along with mine and everyone elses)
see if you can work with actors to perform the math on different threads in your computer.
there are few other tutorials on the devforum about it
you know, i found solution, use tables to lerp positions and send remote event every 1/10th second to get it on client
i really think you should do the animating on the client… sending an event every 1/10 seconds can be expensive on the server and clients. use the remote to tell the client where to animate the object towards and do it there.
yea, but 1/10 is for lerping enemies position, soo towers can smoothly attack on client, animations will be 100% client, no remote required, maybe when state changes but then…
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.