Weird synch issue



  • Hey guys,

    Here I am with another blocker :)
    Let me quickly explain what I did so far and what I want to achieve

    • I am doing a 2 player mobile tanks game which is played with only 1 joystick

    • Red player (master client) fights against the blue player (slave client)

    • I removed the right joystick so the player only controls movement

    • Tanks shoot automatically towards the center of the nearest enemy

    • I’m using TDM mode as default

    • Apart from the above changes, I didn’t really touch any part of the code

    And here’s my problem:

    • Blue (slave) player always lags behind -probably because of network lag and here’s how I measure it: 2 tanks start to go towards the same direction with a little gap between them. Red hits blue while the blue can’t hit red.

    • The weird thing is, things look normal on blue player’s screen, like it’s also hitting the red player, but on red’s screen all blue’s shots miss and since red is the master, those hits don’t get registered.

    • lSo the things happening on blue’s screen are not in synched with what’s happening on red’s

    • I tried unity networking (both internet and LAN), and photon, they all have the same issue.

    • Also tried to increase sendRate in unity networking.

    • Also tried to adjust the server/local modifier in shoot method that tries to compensate for the network lag

    Here's what I suspect might be happening:
    Both clients do act on the enemy position data they have for shooting purposes. So the red (master) always has the latest data while blue might not have the latest at the time of shooting. So red always shoots at the correct (up-to-date) position of blue while blue shoots at the previous step position of red. But since things look okay on blue's screen (it's actually hitting red just like it should) this might also not be the case.

    Can you think of any solution to solve the above problem? Any help would be appreciated.



  • No need to bump, I am reading all posts but might not be able to answer right away.

    Since shooting is kind of server authoritative, the master client does the calculation of shots and registers hits, then sends the result and updates other clients. This is what you've expected already at the end of your post.

    There is no solution to this - lags exist and cannot be avoided, except that this should barely be noticeable with UNET on LAN games. As long as updates have to be routed over a cloud server, there will always be lag.

    You could allow clients to send hit updates to the master client as well, instead of doing the calculation on the master client only. This would open a door to hacking and you have to consider the risk of this for your app too. Note that when doing that, your client could hit the master in his view correctly, however in the master client's view, the master client could be hit by something that would actually have missed. So even that wouldn't be a definitive solution. If you're really into networking, you could look into implementing client side prediction / forward prediction on clients and lag compensation techniques on top. For a general/basic network tutorial asset like Tanks Multiplayer, this was out of scope of the original implementation.



  • Thanks Baroni, that clarified the issue pretty well. Since I don't have a coding background and use unity for basic prototyping purposes, I guess there's not much I can do.

    Btw, I made the slave client shoot a bit ahead of the master client, negating the disadvantage of lagging behind and it looks okay, at least it doesn't feel unfair for the slave.

    Again, thanks for the reply.


Log in to reply