Search Unity

Question Lagging multiplayer problem

Discussion in 'Netcode for GameObjects' started by Christian_Perri, May 5, 2023.

  1. Christian_Perri

    Christian_Perri

    Joined:
    Aug 7, 2022
    Posts:
    31
    Hi guys,i tryed to run the multiplayer of the game and i am having problems,there are 2 players and 1 disk,everytime a player hit the disk the ownership of the disk change.When i am the owner of the disk the gameplay is perfect and there is 0 lag,but than when the other player hit the disk the movement of the disk is "lagging" and the gameplay is not good to play,here there is a video of the gameplay
    .
    1. Do you think it is a client-prediction problem?cause the movement of the objects when i am the owner is perfect and there is not input lag
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,521
    Instead of changing ownership every time you hit the disc why dont you just calculate the correct position on the server/host and replicate that on clients?
     
    Christian_Perri likes this.
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,909
    In a Host/Client 1:1 game the Host will always have the advantage of zero lag. Competitive 1:1 games should have an authoritative server instance so both players have the same handicap or at least would have if they had the same ping to the server.
     
    Christian_Perri likes this.
  4. Christian_Perri

    Christian_Perri

    Joined:
    Aug 7, 2022
    Posts:
    31
    i could also try it,i was doing the changing ownership cause it was more intuitive,so you are saying that when the client hit the disk i should send a server Rpc and change the position of the disk?
     
    Last edited: May 5, 2023
  5. Christian_Perri

    Christian_Perri

    Joined:
    Aug 7, 2022
    Posts:
    31
    The fact is that when the client has the ownership of the disk the game is not lagging from the view of the client.
    In this case the client-prediction doesn't help correct?
     
  6. Christian_Perri

    Christian_Perri

    Joined:
    Aug 7, 2022
    Posts:
    31
    Updating,i changed the code and now there is not the passing of the ownership when a player hit the disk.
    I removed the Network Rigidbody component from the disk cause it became kinematic and for that reason the disk didn't move.
    Now when i am the host everything works great,the movement of the disk is perfect when i hit the disk and when the client hit the disk.
    But when i am in the view of the client the things are bad,the disk is constantly lagging when i hit the disk and when the host hit the disk,it is like the host doesn't manage to keep updated the position of the disk.
    Do you thing this could be the problem? How can i solve this problem?
     
  7. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,521
  8. Christian_Perri

    Christian_Perri

    Joined:
    Aug 7, 2022
    Posts:
    31

    Attached Files:

  9. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    258
    While this example doesn't address all potential issue regarding lag (and the like), I figured it might help you resolve the issue with your puck. When you finish your game let me know... I love air hockey! :)
    Just create a stand alone build and run a couple of instances. One as a host and the others as clients.
    Make sure that the host is selected (the "host" text will be fullbright red like the host's player color) and hit the space bar to cycle ownership of the "follower" ball that is using an owner/client authoritative NetworkTransform so that the newly assigned client owner controls the "follower". For fun I apply impulse force to the ball.
    upload_2023-5-17_18-2-41.png
    You will notice a "transparent" purple-blue ball and then the "visual" aspect which lags slightly behind it. The "transparent" purple-blue ball is the actual NetworkObject with the NetworkRigidbody and NetworkTransform (set to owner-client authority) and the ball with the material is the "ghost" client representation.
    upload_2023-5-17_18-7-55.png
    The basic idea is to separate the "visual" portion from the actual NetworkObject itself for this type of scenario where you could have "gaps" between changes in ownership due to interpolation and the time delta between clients. I didn't do a full blown client prediction system, but it provides a reasonable end result.

    With the puck, you could still run into some gaps between collision and the visual part which that depends upon the collider and who is detecting the collision.

    As opposed to changing ownership when the disk is hit, you might consider changing ownership when the disk crosses the middle of the table
    coupled with something like the splitting of the visual and the NetworkObject itself you might see a better end result.
     

    Attached Files:

  10. Christian_Perri

    Christian_Perri

    Joined:
    Aug 7, 2022
    Posts:
    31
    thanks man,sorry for the waiting,i just hired a person to write for me the client-side prediction