D
D
dollar2018-09-04 22:59:33
Game development
dollar, 2018-09-04 22:59:33

What to do if the coordinates on the client and server do not match?

The player presses the right arrow - the character starts moving to the right (in real time).
On the client - at once (prediction).
On the server - with a delay of 100 ms.
Next, the player releases the arrow to the right - the character stops.
On the client - immediately (it sends a stop signal to the server).
On the server - after 100 ms (while sending the coordinates of the last position to the client).
But the local and sent coordinates do not match, because ping is always slightly different.
How to be?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
X
xmoonlight, 2018-09-04
@dollar

We always bring the interpolation braking of the character on the client using the server coordinates.
1. Released to the right
2. Sent to the server and received the coordinates of the stop
3. Slowly, within 10-15ms (if it is moving at this moment) and 250-300ms (if it is frozen in place and does not turn), we put it in this position.
If you keep the entire game world on the server, then the server is always the main one .
UPD: I will add that you can also later check on the server by calculating the coordinates from the client and do reverse tests on the event checkpoints on the server to give a conclusion about the correctness of the event calculated by the client.
For example, in order for a hit to be recognized as counted from exactly these coordinates and from this particular weapon, you need to check in the opposite direction (along the timeline of events) the point of the shot and the possibility of a shot, the path of movement and the time between the previous check and the current one.
That is, restore, based on a number of factors, the previous state of the player that was not sent (or has not yet been delivered) to the server between packets due to the duration of the ping.

D
Dmitry Alexandrov, 2018-09-05
@jamakasi666

In your particular case, the answer is very simple.
The client predicts its position, but the server must respond with coordinates of where the client is located and this answer will take precedence. To make it all work correctly, synchronize the client and server according to server ticks, and therefore store the last N states of the world on the server and client, i.e. the following scheme will be obtained:
The client predicts its position and sends to the server that I am moving to the right tick 10
The server received the packet, looks at the tick, rolls back the state of the world to this tick and sets the movement to the right.
The server sends the state of the game world to the clients with its tick number.
The client, having received a packet with its coordinates and the server tick, rolls back the world to this tick and looks to see if the prediction of the coordinates is correct. If you guessed correctly, then you don’t change anything, if you didn’t please, then rollback to this position and listen to the server further.
In addition, this mechanism will immediately solve problems with shots and interactions. the server can restore a picture of what the player saw at a particular moment in time and whether he could hit the object / player.
In essence and in simple words it looks like this:
The server is always in the present time but can look into the past.
The client always sees the past state of the world, but he (and the objects with the prediction) are in the present.
In addition, the server can (more precisely, must! ) introduce an artificial delay for clients (within reason, calculate the average for all clients or some fixed one), this is guaranteed to make all clients see the same state of the world regardless of their network delay.
Here it is in a nutshell and in simple terms.

O
OnYourLips, 2018-09-05
@OnYourLips

Now look from the position of the shooter. If the client hits another character, then he must hit.
So the server is not the main one. Naturally, anti-cheat algorithms become much more complicated because of this.
On Habré there was a series of articles about the network part in Overwatch (one of the leaders among competitive shooters).

P
Pavel K, 2018-09-04
@PavelK

Coordinates use "range" adjusted for ping.
For example, we find out the delay between the client and the server in 100 ms, we know that during this time the player can move, a maximum of 5, so on the server we mean that the client can at this moment be from the current sent coordinate in the sphere by + -5 . In some cases, it's generally better to set the communication immediately client<=>client, but then it's up to you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question