Advertisement

How to sync a basic network game as close as possible between clients

Started by September 26, 2017 01:04 AM
1 comment, last by Kylotan 7 years, 2 months ago

Hi

I have a very basic prototype in unity of a game where by I fire a projectile with a obstacle in the environment that moves blocking its trajectory.

 

Due to the fact that time between events is obviously not instant between clients i have a slight issue where one user shoots the projectile and hits the target, but the other player sees it miss the target entirely.

Picture to explain better:

fypJ6xN.png

The main problem is that the position of the moving obstacle is not in the same position "now" upon the firing event received for client B as it was for client A.This is not an FPS or something like that, the moving obstacle is part of the environment rather than another player. So i am thinking i should be able to get this moving obstacle sync'd far better than i could with player positions. 

Now i know this is not 100% solvable due to the nature of networks but am wondering what solutions i can implement to reduce the amount of error for this.

The simplest approach is to decrease the time difference between the various participants so that discrepancies due to latency are minimised. In many games this is just a case of sending network updates more frequently or more immediately, or responding to them more quickly.

A more complex approach, is to perform any relevant game logic based on what the player would have observed. Obviously there is more than one "the player" so usually it's the actor whose perspective is respected - in this case, the firer (Client A), not the observer (Client B). Sometimes this process takes the form of a full process of rewinding the game logic and replaying it from the client's perspective - other times it is as simple as ensuring the game respects the actor's timescale (e.g. being specific about exactly when the projectile was fired, based on Client A's report, rather than letting Client B generate and manage its own copy of the projectile slightly later in time.) Note that these approaches all facilitate potential cheating as a client can lie about how much latency it is experiencing.

This topic is closed to new replies.

Advertisement