Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    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:
    2,084
    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