Unity authoritative networking

http://www.edje.net
A demo i made with Unity’s networking and the character customization models with lag compensation.
If no other games available you can test with a second window.
It’s a full authoritative config so all clients send the input to the server and the server execcutes the commands.
More things will be added but if someone finds a bug please post it.

I’m just curious, but do you also process the movement on the client for predictive behaviour? It feels like you don’t as it’s a bit laggy for clients.

I just checked and client side prediction was disabled during testing. I will upload a new version with client side enabled also.
Thanks for the info.

hi. so is this authoritative server is something your physical server? (server hosting company’s or your local server computer)

nope, the user that starts the server instance is the auth server. all client players that connect have to send all the input to the server, server validates and executes and sends the updated gamestate to the clients.
No hosting involved, the server is started on the player’s computer.

Looking good appels, smooth network experience on my end.

thanks

appels, could you share the project files for this?

I’m struggling with lag compensation on an authoritative server. I have experimented with the NetworkRigidbody and GraduallyUpdateState scripts, but I still can’t get the client movement smooth.

basicly grab the GraduallyUpdateState script and use it on all clients.
also make sure the right owner is set.
it should work ok on a third person network player.
i’m working on a first player version which is alot harder to achieve.

Thanks for the reply.

Yes, it took me a while to get the SetOwnership working correctly, since I added it to Leepo’s authoritative tutorial. Maybe I should have built the game from the network example instead.

I’m using rigidbody.AddForce for movement so perhaps that is confusing me. I will persevere with the GraduallyUpdateState script. Thanks for the tip.

Hmm, I switched everything(player controls, serialization etc.) back to transform instead of rigidbody and it works perfectly, really smooth. I can’t see why this is; NetworkRigidbody and GraduallyUpdateState are very similar yet GUS is very jittery when modified for rigidbodies.

Anyway, I must not hijack this thread any further. Thanks for your help.

Have you found a solution for this on rigidbody yet? I’ve implemented Leepo’s authorative example in my multiplayer game and the server side runs very smooth but I have trouble getting the client side smooth with perdiction. I’ve enabled interpolation and I play the physics on the client side for “perdiction” although I haven’t implemented proper perdiction with state replay yet - something I gather GraduallyUpdateState script does.

I ask this because I’m currently controlling my player objects with AddRelativeForce to the Rigidbodies.

We are trying to achieve the same thing, imphy. I’m surprised nobody has done this before to be honest.

Unfortunately, I have hit a brick wall. I had better results moving the player movement to FixedUpdate, using rigidbody.MovePosition to correct, but it is still not smooth enough for me. I tried factoring velocity in there too but it made little difference.

I read about how Unity’s physics is maybe not deterministic, so perhaps rigidbody prediction is always going to be too far out.

If you ever find a solution please PM me.

I am having the same problem, with a vehicle, it has a rigidbody, and uses wheelColliders to move around (WheelCollider.motorTorque and WheelCollider.steeringAngle)

I tried many variations of the Interpolation/extrapolation scripts i found on the internet and in the Unity’s Networking Tutorial, with no luck.

the smoothest result i got was when i serialized the velocity of the rigidbody and applied it on the RemotePlayer, tho i am sure this is not the right way to do it, because you have to limit framerate, have a FixedTimeStep equal to 1/Network.Sendrate and make sure your packets are small.

All you need to do is set rigidbody.interpolation to interpolate, and make any changes in propulsion or anything in FixedUpdate().

Decently simple (not that I would recommend running physics on the server, but still):

  • Attach rigid-bodies to the game objects on the server, but not on the clients
  • Serialize the data from the server to the client
  • De-serialize on the client, put into a buffer which is an array of the latest states and what networktime they arrived at
  • Find the two states in the buffer which is before and after the current time
  • Interpolate between them

I’m quite happy with the way I’ve got things working at the moment, but I’m not sure I’m doing it right =) A bit new to Unity still.

I’ve opted for a model where I use Authoritative server (based on Tutorial 3 of Leepo’s networking tutorial) - but what I did was attach the NetworkRigidbody.cs script to my player and I set the NetworkView to observe the NetworkRigidbody.cs script. I still send keystrokes from the clients to the server and the server performs authoritative movement but the client side prediction works very well this way (unless I’m totally misunderstanding things =)

Currently my ships moves very smooth locally for every player and I’ve only been able to test it with 30ms latency but I’m happy with that result so far as well.

When one player is connected to the server and one of my players are moving and rotating I seem to cap out on about 3000 bytes per second - that sounds fair to me.

I run physics at time step of 0.02 (50Hz) and I’ve decided to put input capture and mouse aim functions in FixedUpdate() to minimize the number of RPC calls to send player input (I rand without VSync with a framerate of 1100 FPS and my mousaim Vector3 delivered 64000 bytes alone =). Be aware though that I am caching ButtonDown and ButtonUp from Update() as they don’t work properly in FixedUpdate().

What is the percentage of modern day realtime, client-server multiplayer games that are fully authoritative? Not including MMO’s?

Server side will allways run smooth since it’s commands are processed localy.

I just modified my setup with rigidbodies and i still have some small bugs but the lag compensation is working and the movent is as smooth as with the CharacterController i used before.
I didn’t have any problem at all, even used the same lag compensator script then the CharacterController setup.
What are you sending over the network ? Just the commands or something else ?

See my most recent post. It’s now also very smooth on the client side. I send client input from the client to the server so it can calculate the authoritative physics, but I’m also currently using the NetworkRigidbody.cs script as the observer on the object and I’m not sure if the client transmits any of that data to the server =) It’s all a bit of magic for me at the moment but I am surprised over how smooth it is on both client and server side. Then again, I’ve only been able to test it at 30ms latency - I’ll have to connect using my 3G modem on my laptop to get some better data.

The NetworkRigidbody.cs should contain the interpolation so yes that is the right way to do it.