Sending Large Tables To The Client 10 Times A Second
I am making a tower defence game, and the way it works is by having a heartbeat on the server that runs 10 times a second, to calculate the new position of each enemy depending on his speed and the frequency of the heartbeat, then after all the enemies are done it will send the table of enemies to the client so it can replicate it on the enemies, my question is what would be the best way to send this table to the client with the least bandwidth usage ? My current approach is JSON encoding it then compressing it using ZLib Deflate string compression library and sending it to the client where it will be decompressed and decoded.
I have also thought about using buffers or bit packing for handling that, but still not sure which one would be the best, or if there is an even better way or not
64 Replies
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
you mean just inform the client when an enemy is spawned and it will calculate on both the server and the client without having to send it again ?
the current approach i am taking of sending the data at set frequency each second is to be able to capture all the changes that happen to the enemy, not just his movement, many other stats can change multiple times and for multiple enemies, and replicating them each time can sometimes create some de-sync with the server which causes displacement with some enemies and many issues
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
hey! i did this for my tower defense game. zlib is inferior, and your other thoughts are spot on. buffers/bitpacking is the way to go. if you're using flamework, theres an amazing package by @Fireboltofdeath called @rbxts/flamework-binary-serializer that takes a type and automagically serializes your data into a buffer. even allows you to specify number sizes like u8 or i16. i used this for my TD game and it works phenomenally.
to save more space i also send a number representing the enemy's distance along the path, then calculate where they should be on the path with that number
do you think just sending it's X, Z positions is good idea ? for the movement
alright i will make sure to check the binary serializer and try to edit the system to work with it. also just to have a reference, what's a good bandwidth usage range for 100 enemies spawned ?
hits and some abilites can edit enemies speed/position so i wouldn't say it's a fixed pattern
i will see about that
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
that's concerning 💀
i just send one number: distance
with the distance along the track u can calculate their exact cframe on the path at that distance
i can send some code if needed
disagreed you can send a distance number at 5-10hz and lerp the movement on the client, thats what i did and it works flawlessly
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
now that i think about it, that does make sense
instead of 2 numbers, just 1 number for the position which is the distance
right
and then i use the map's path data + bezier curves to calculate an exact cframe at the given distance
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
not necessarily
you can just label the path nodes differently
and generate 2 diff paths
and pick which one to use at random
multiple paths = multiple bezier curves ? probably maximum 4 paths and bezier curves are just some math calculations
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
u can just use 2 paths
u dont need to send any extra data
u calculate it all on the client
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
all you need to send is a distance along the path
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
i literally did it in my game bro lmao
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
if theres 50 roads u still send a distance along the path
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
the client will decide which path the enemy uses
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
not the server or any remote
and nothing more
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
u said u would need to send more data
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
💀
this guy is something
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
oh yeah it matters so much if a hacker makes an enemy choose path B instead of path A
come on bro
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
fair point actually
it will work but desynced
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
could just send an extra u8
ez
the server tells the client everything at the spawn of the enemy, and then just sends it the distance at a set frequency and the client moves it according to the info that was sent initially and the distance that's being sent every now and then
path id like u said ig
i think you need to learn some client/server architecture more though
the server keeps track of the enemies distance along the path
the client just sets the enemies cframe
so anything like attacking still checks the distance along the path from the server
so the solution for using multiple paths is to just send an extra path ID field
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
i said the same thing xd
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
yep
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
💀
UwU
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
doing anything on the client is more performant than doing anything on the server
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
so we track the important stuff on the server
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
then delegate unimportant stuff like vfx, updating positions, etc to the client
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
hackers cant do anything
important stuff like how far the enemy is along the path is on the server
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
towers use the data from the server to attack, etc
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
correct bc physics on the server is incredibly expensive
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
(All clients are hackers)
lol
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
lmao
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
wdym a shared table ?
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
ah never worked with parallel