- Home /
Networking physics with HLAPI
Hi, I'm creating a very physics heavy based multiplayer game. So far I have tried three options for the physics calculations:
All physics calculations are run by the server and all GameObjects whose movement depends on the physics have a NetWorkTransform component attached.
All physics calculations are done locally by the clients.
Physics calculations are done by server andall clients and I'm trying to synchronize them with NetworkTransforms
All 3 options causing issues:
Causes discontinuous, non-natural looking behaviour on the client side
Since physics calculations are not deterministic + delayed Input due to latency leads to different movement on all clients and sometimes different game results
Actually the solution I am most optimistic about to work, but right now it's pretty jerky. I think thats because every frame the server is correcting the clients calculations (What is actually the right thing to happen but I'd prefer to have it smoother).
I'm wondering if there is any chance to get this work using UNETs HLAPI. Or is using NetworkTransform not sufficient and I have too look deeper into how Network Syncing works and maybe use the LLAPI/ Transport Layer (Haven't worked a bit with it yet and was hoping to avoid it).
Setting the Netowrk Transform Send Rate to the maximum value improves it a little bit but still not perfect and I'm not sure if this is the optimal solution
There is a chance to get this work using UNETs HLAPI, but using NetworkTransform is absolutely a no-go. I had the same issue or maybe still have it. $$anonymous$$y solulution was to make custom NetworkTransform, in which i sync needed vars just via [SyncVar] attribute, and a Networktime class to have a reference to a time variable that is exact same for everyone. then in my NetworkTransform i calculate predicted position and rotation, that should happen not now, but when next sync event occurs, and change rigidbody angular and normal velocity the way, it will be in that calculated position and rotation when next sync event occurs. Works 10x times better than unity's built-in NetWorkTransform, but still poorly. Has it's own bugs if not synced for a long time, because physics is very very different from what is happens on server
Thx, right now I'm really considering swithing to PHOTON. All the tutorials and documentation about UNET just seem to scratch the surface.
Answer by mhernandez88 · Feb 12, 2018 at 11:29 AM
For #3 you are going to want to seperate two ideas Interpolation and Extrapolation. You are also going to want to have a couple of variables Position Snap Distance - how far off do we correct Rotation Snap Distance - how far off do we correct Interpolation Back Time - how far back do we go in messages in order to smooth Extrapolation Time Limit - how far forward can we extrapolate physics Extrapolation Distance Limit - how far from last network position can we extrapolate physics
Extraplation will consist of basic calculations using rigidbody properties.
You will want to make sure to be syncing Velocity and maybe even Angular Velocity
I am currently working on this, I got the smooth syncing working mostly, but you need to fool around with the variables.
By the way, you are going to need to simulate latency and update interval
Your answer
Follow this Question
Related Questions
Need help getting "Server Reconciliation" to work. 0 Answers
Sending texture updates from client to server 1 Answer
Unity networking tutorial? 6 Answers
How to check when a new client/local player is loaded? 1 Answer
How can i make multiple game instances in one server or multiple servers? 0 Answers