- Home /
Network client side Prediction and gravity server-client different
Hi everybody. I'm making basic multiplayer shooter in 2D with model in 3D for my studies with a authoritative server . Actually i try to go over the client prediction to have smooth movement in the client-side. So what i basically doing is to apply the same movement logic in the client side while the server apply it's own movement logic and correct the client-side position with the server if there is too much difference. But i'm facing a big problem. The gravity is not apply on the same way in the server-side and the client-side i mean the client-side for example jump a little bit less than the server-side. And that apply a big desync between the two. I try to figure out what can happen and i think the problem is the frame-rate. I use a character-controller for the controller with my own implementation of the movement logic the script is the same for both client and server. So i try to understand how to be fully fps independent. Actually this is how i calculate the gravity movement.
verticalSpeed -= gravity * Time.deltaTime; // apply the gravity
Vector3 movement = new Vector3 (
horizontal * trotSpeed,
verticalSpeed,
0);
movement *= Time.deltaTime;
collisionFlags = character.Move(movement); // apply the movement
What's wrong with the short part of code why the server jump a litle-bit more than the client. Did i make a big mistake on the way i calculate my gravity ?
Thanks in advance for the response.
Yubi for more explication i advice to reffer to this doc : http://www.gabrielgambetta.com/fast_paced_multiplayer.html http://gafferongames.com/game-physics/networked-physics/ https://developer.valvesoftware.com/wiki/Source_$$anonymous$$ultiplayer_Networking
For the movement the lag compensation is really easy just save all the position after the movement command in a circular buffer. and when the server send the response check if both have the same result. If they don't have the same result rerun all the simulation (in accelerate) from the last known server position.
Yes I understand how it works, but I expected the problem you are seeing might be related to latency. But I see you have investigated that already. $$anonymous$$aybe you have somewhere any rounding problems, e.g. with floating points?
Yeah i look into the floating point and the problem with networking game during my research. And i think the major problem with my implementation is the difference between the frame-rate of the client and the server. I mean at the begining i was using update in both client. But if you take the jump example the frame when both detect the apex can be different of 1ms so one gonna be upper than the other. And is the same for walk if i push left for 1ms the player must move at walkspeed 1ms But if the frame take 2ms on server and 1.5ms on client. the server move : walkspeed 2ms. and the client move: walkspeed * 1.5ms so both will have different position. So the only way to solve that is to use the FixedUpdate so both have the same rate of frame while processing the movement.
Another probleme i'm facing right now is. The time between when the server apply the movement and when the server send the updated movement to the client. It take between 1.96sec and 2sec oO. it's really really slow why the networkview take so many time to sand the information ?
Answer by Chibiliplop · May 18, 2015 at 10:40 AM
Finally after more and more documentation about the client-side prediction and reconciliation. I success to avoid the problem by performing all the movement of the client and server in a FixedUpdate so both have the same simulation. If it's differ just rerun the simulation from the last know position of the server.
The next problem is how to implement the lag compensation with unity for the shooting. The rewind sound difficult with a raycast.
Your answer
Follow this Question
Related Questions
Infinite/procedural multiplayer world in Unity possible? 2 Answers
Clientside Prediction in the Networking Example 2 Answers
Client side prediction from the Networking Example 0 Answers
Network problem player lag/jump when move with autoritative server and interpolation/prediction 0 Answers
Trying to send command for object without authority. - change color of object from client 0 Answers