Search Unity

movement will never be smooth using HLAPI

Discussion in 'Multiplayer' started by okokdreamy, Jan 25, 2016.

  1. okokdreamy

    okokdreamy

    Joined:
    Jan 25, 2016
    Posts:
    2
    Hello,

    I have been trying to do make a small 2d platform multiplayer project using UNET HLAPI and it seems that it is impossible to make any movement smooth between clients, and even on the same computer!

    Any input from the Client to the server will still be okay. However, With at least 3 players (1 server and 2 clients), We will already see jitter movements between clients... Would it be that the hook at the Syncvar causing issues or something?

    I have tried several stuffs (enable/disable Local Player Authority), enable/disable network transform and edit the values, tried my own prediction/reconciliation script, followed some tutorials in youtube but I am still unable to accomplish somethinig in which I am happy with, and essentially in 2d.

    So my question is, is there really a solution for that? Did someone manage to make UNET working smoothly?
     
  2. Zebadiah

    Zebadiah

    Joined:
    Apr 6, 2014
    Posts:
    67
    Check the QoS channels in the Advanced Configuration section of your network manager. You want to make sure things like position updates are going over a channel that is set to State Update.

    You can set the channel that a script's syncvars will use via the [NetworkSettings] Attribute

    You can even set the channel that individual Commands and ClientRpcs will use

    I'm actually less sure how to control which channel the NetworkTransform uses. I think you can create a new script that extends from NetworkTransform and either use the [NetworkSettings] attribute or override GetNetworkChannel(). Leave the rest of the script blank and use it instead of the standard NetworkTransform component.
     
    Anisoropos likes this.
  3. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    That's totally normal behaviour. It's up to the server to guess how a client character will be moving based on the last state, and up to clients to smooth things out based on what each character was doing last. At any given point, what's happening this time is almost always what was happening last time.

    https://en.wikipedia.org/wiki/Lag
    http://web.cs.wpi.edu/~claypool/courses/4513-B03/papers/games/bernier.pdf

    Also look up prediction, extrapolation, interpolation, lag, packet loss/delay, rubber-banding, etc. There are a ton of things that will go wrong; this is where your coding can help smooth things out, but never get rid of these problems altogether.
     
  4. chenyuchih

    chenyuchih

    Joined:
    Jun 3, 2015
    Posts:
    37
    If you are using NetworkTransform.SyncTransform, this mode just sync position in period, no prediction or interpolation. If you want it move smoothly, use rigidbody or write custom handler.

    If you use rigidbody2D/3D, you must set the "Interpolate move/transofrm" as 1.

    If you still meet jitter illusion, maybe you re-compute the position at client again. Just compute position at client with authority.
     
  5. Anisoropos

    Anisoropos

    Joined:
    Jul 30, 2012
    Posts:
    102
    Thanks for the pretty easy to implement solution. Still wondering why it's not exposed by Unity in all network components.
     
  6. xdd7777

    xdd7777

    Joined:
    Nov 16, 2015
    Posts:
    3
    Thanks for your suggestions