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. Dismiss Notice

Question Time.DeltaTime inside GhostPredicitonSmoothing Delegate?

Discussion in 'NetCode for ECS' started by Misterturtle, Sep 24, 2023.

  1. Misterturtle

    Misterturtle

    Joined:
    May 25, 2017
    Posts:
    20
    I imagine it's a common use-case to smooth movement based on time for a natural look. What options are available?

    My only thought currently is to maintain a "copy" of Time.DeltaTime in a component that is passed in as a UserData Parameter Component. Seems potentially error prone. Any better options?
     
  2. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    774
    Storing the delta time is not necessary and can't really control the way the value is going to be smoothed.
    There reason is that the GhostPredictionSmoothngSystem is used to fix for prediction error (not smoothing in general the movement or whatever).
    The smoothing is called inside the prediction loop only for full ticks, given the way it work, and it try to adjust the error in between the current predicted value (based eventually on the new receive data from the server), and and last prediction backup.
    If there is no prediction error, the delta in between the predicted and the current backup is 0. Otherwise, an adjustment to reduce the error is done.

    This adjustment is performed only when the current NetworkTick equals the tick of the last backup, so either a rollback must have occurred.
    The adjusted new value of the component data is then stored in the backup and will be used as new start prediction point for the subsequent new simulation ticks. As such, the smoothing does not occur until a new update from the server are received and new adjustment will be made.

    It does not run every frame or partial ticks, so storing the delta time would equals store a fixed value of 1f/SimulationTickRate.
     
  3. Misterturtle

    Misterturtle

    Joined:
    May 25, 2017
    Posts:
    20
    Ah, makes sense. Thank you for the clarification. I'm still wrapping my head around what tools/interfaces/Singletons/concepts are available for helping hide network latency. The more I think about it, smoothing movement based on a server correction instead of teleporting should really only occur in a worst-case scenario. The majority of latency correction will be hidden inside animations/forced input latency/action lock windows.

    I just found some singletons like ClientServerTickRate, ClientTickRate, NetworkSnapshotAck, and NetworkTimeSystemData. These seem rather important to understand before being able to hide latency precisely. If you know of any resources/previous threads that give an overview of these concepts, that would be very helpful. If not, thank you for the previous answer to help set me on the right path!