thefollower

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

Recommended Posts

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.

Edited by thefollower

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now