Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Client Prediction and Lerping on Host??

Discussion in 'Netcode for GameObjects' started by wadwitch, Nov 7, 2022.

  1. wadwitch

    wadwitch

    Joined:
    Jul 1, 2015
    Posts:
    2
    Hey everyone - I'm playing around with the unity netcode for gameobjects and I just got client side prediction and server reconciliation to work (yay for me). In order to keep movement looking smooth I need to lerp, but in order to keep the movement deterministic I can't lerp. Here's the state of things:

    Client:
    If client is the owner, handle movement normally and send inputs to server. Reconcile any differences with server.

    If client is not the owner, use fancy lerp to lerp towards latest state recieved from server.

    This makes the movement look really smooth on the client side.

    Server:
    Move each player based off the queue of recieved inputs and send resulting states to clients.

    Slightly choppy - but its deterministic and looks dont matter that much for server.

    The issue comes from hosts - which are both server and client. The local player's movement is smooth since they're in control, but the other players have the deterministic / choppy appearance of the server clients. I'd love to smooth them out, but the only workaround I've found is lerping the character model's position and not the character controller. This causes issues with the host aiming at a target whose hitbox is a ways away.

    Netcode Veterans of unity - any ideas?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,514
    Just a thought: proxy objects. Simulate movement of player objects on server-side that default to not rendering at all. If the server is also a client, then draw client player representations that follow (lerp to) the proxy client objects.
     
  3. wadwitch

    wadwitch

    Joined:
    Jul 1, 2015
    Posts:
    2
    I guess that what I'm kindof doing now? interpolating the position of the child character mesh to align with the server position as opposed to interpolating the position of the player gameobject. Hopefully when I move onto adding the colliders for the characters I can parent them to the mesh so that it wont cause any weird issues with aiming at a player and the player's collider lagging behind