- Home /
How Do I Reduce Lag in my Networked Game?
Hello, right now I have an operational networked game - but one that is plagued by an enormous amount of lag. In the game, you basically are a car that can shoot other people (who are also cars).
I have set the rigidbodies to "interpolate" and the Network Views to "Unreliable" with little to no effect.
Is there anyway to reduce the lag further?
Sincerely, CarbonTech Software Admin
Answer by Murcho · Jul 06, 2010 at 07:10 AM
The best technique I've found is to use a prediction system. The basics of which are to have a local version of the actors that the local player can see, and an invisible version which is linked as closely as possible to the server data.
The local visible one is updated based on local input, so it predicts where the server will tell it to be. Then when the server sends back a message telling the actor where is should be, the invisible one is moved immediately to that point, and the visible one is smoothly interpolated to that point.
It's a tricky system to implement, however it is (in my opinion) the best way to do things. The Source engine uses this system in all of it's multiplayer games (Counter Strike, Team Fortress 2, etc.). Here is an article on their wiki explaining how they do it.
EDIT : Note that while this won't directly change lag, it will change the way the player perceives the lag. You should still try to optimize the amount of data being sent.
$$anonymous$$urcho, I'm a little confused about this. The article you refer mentions 3 techniques: -Entity interpolation. -Input prediction. -Lag compensation.
What I understand you are saying is not doing Lag compensation neither entity interpolation, but something like input prediction with all entities. That would be, for example, execute AI code in the client in each tick and interpolate the result with the actual value received from the server. Is that how you did it ?
The three techniques are mixed with one another. For players you predict based on input, for AI you predict based on what your AI rules are, and you interpolate/extrapolate your data from there, always adjusting once the server data is received. It's been a long time since I implemented this system so sorry if I'm a bit rusty with it.
Answer by JRitchey · Nov 28, 2011 at 05:35 AM
If you are trying to use the same NetworkRigidbody.cs script as the Network example, there is a small detail you may have overlooked. I got lucky in finding it in an out-of-date Unity Tutorial.
All you have to do is change the 'Observed' field in 'Network View' on your prefab from 'PrefabName(Transform)' to 'PrefabName(NetworkRigidbody)' by clicking and dragging the 'NetworkRigidbody(Script)' component into the 'Observed' field.
This solved my lag issues.
that solved my problem. Such a dark trick! Thanks JRitchey
Anytime... The NetworkRigidbody script does the same thing they're talking about in the other answers (Dead reckoning and prediction). The Networking sample has scripts that do this for other types of objects as well.
Hello, I'm having the same problem and I believe this is where my problem lies. Although, I cant seem to change my PrefabName(Transform) within the Network View by dragging the NetworkRigidbody script? What am I doing wrong?
worked for me ty man i had sum crazy problems till i found this
Answer by qJake · Jul 05, 2010 at 08:21 PM
The only thing you could do, besides optimizing what you send over the network (which you have to do, we can't help you with that), would be to increase the Sendrate, found in Edit > Project Settings > Network.
From the UT docs:
The data that is sent at the Sendrate intervals (1 second / Sendrate = interval) will vary based on the Network View properties of each broadcasting object. If the Network View is using Unreliable, its data will be send at each interval. If the Network View is using Reliable Delta Compressed, Unity will check to see if the Object being watched has changed since the last interval. If it has changed, the data will be sent.
Thanks. So there is nothing else I can really do? Would making the ridgidboy extrapolate decrease the lag better than interpolating it?
Answer by matthew 1 · Aug 13, 2010 at 06:58 PM
sometimes your signal will go bad so if you have wireless internet server just disconnect and connect again and if that dont work and the lag is incredably slow i would contact your internet provoider for ore info.
Answer by Stardog · Mar 28, 2014 at 10:25 AM
This tutorial shows interpolation and prediction of a Rigidbody:
http://www.paladinstudios.com/2013/07/10/how-to-create-an-online-multiplayer-game-with-unity
Question is already answered, but the tutorial is great.
Problem with this tutorial is that his examples are incredibly contrived and the solution he proposes doesn't actually work in a "real" game where a lot of things are going on at once.