Forum General My game has too many units and it's flooding the network

Any issues or discussions relating to Unity development are welcome here.

My game has too many units and it's flooding the network

Postby jasonredhawk » March 25th, 2021, 1:03 pm

I've got a game that each player is controlling multiple units. Currently, I have it such that every unit in the game sends its position and rotation to the server (at 60fps speed in Unity's Update() method) and then broadcast to all other players. I'm testing using about 20 units and it seems to be flooding the network and the game disconnects. Does it make a difference if each unit is sending its own Message.Create(), or is it more efficient to create one Message.Create() and then message.add() all the unit positions & rotations into one large message?

I'm sure there's a better way.
jasonredhawk
Paid Member
 
Posts: 24
Joined: April 4th, 2013, 9:15 pm

Re: My game has too many units and it's flooding the network

Postby jasonredhawk » March 28th, 2021, 7:52 pm

So after further thought and realizing I can't send that much data all willy-nilly, I came up with an alternate plan that seems to be working quite well.

After reading this article https://www.gamasutra.com/view/feature/131503/1500_archers_on_a_288_network_.php I then understood that the client can handle a lot of the animation with only a little bit of direction. So instead of sending a ridiculous amount of messages per frame per unit, I'm sending one coordinate of where the unit should be heading towards and let the unit lerp to that position. This way I send a lot less data per frame and only one Vector3 of data for position and no rotation data is send because the client can re-orient to the new position.

Now in my game, my units use a linepath to follow along, this way a single player can move many units and they each follow their own linepath. So now when a player is drawing the linepath for the unit to follow, those points are broadcasted to everyone, and then let the client animate the units along that path. Super fast, no lag.

Now I do have aircraft in the game where players don't use linepaths but instead take control and fly the aircraft. So in this case, I do need to send more data but a single player can only control one aircraft at a time, so it's contained. When the player isn't controlling the aircraft, the auto-pilot kicks in and continues to fly in the same direction and angle/pitch/roll with the same velocity, again, all able to handle clientside with animation lerping.
jasonredhawk
Paid Member
 
Posts: 24
Joined: April 4th, 2013, 9:15 pm

Re: My game has too many units and it's flooding the network

Postby Emalton » March 31st, 2021, 1:40 pm

Nice! Our game clients pretty much just broadcasts key press data and the other clients interpret that and simulate the physics on their end.
Emalton
 
Posts: 86
Joined: June 28th, 2013, 3:49 am


Return to General



cron