Search Unity

Question NetCode: need help with prediction

Discussion in 'NetCode for ECS' started by PhilSA, Sep 27, 2020.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I've been trying to figure out prediction using the Netcube sample, but I'm not sure if it's working in that project. When I try moving the cube around with any amount of delay, I can clearly see some network jitter happening. The problem is visible with a 50ms delay, but here's with a 500ms delay to make it obvious:
    https://i.gyazo.com/9b9cbef15acf86b5a17de52201ebc079.mp4

    Here, I only move a few meters to the side with my input. But then half a second later, the netcode makes me go back to where I started and move again. This means prediction isn't working as expected (?) It's as if my pos/rot received from the server just got reapplied without actually re-running the prediction frames to fast-forward to the present.

    Does anyone know if this is normal and/or how to solve it?
     
    Last edited: Sep 27, 2020
  2. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I also kinda have a side-question to go with this: am I correct in assuming that all the physics systems (Build + Step + Export + End) should be moved to the prediction group if we have predicted character controllers that can collide with each other?

    I'm thinking the issue with collision world history in this case would be that it wouldn't be updated to reflect the new data we got from other characters since the physicsWorld snapshot was taken
     
  3. wechat_os_Qy0zfuyEv3KJOsvT_cd-jV0I0

    wechat_os_Qy0zfuyEv3KJOsvT_cd-jV0I0

    Joined:
    Apr 29, 2020
    Posts:
    7
    This is a problem interesting but complex, need help..
     
  4. kanesteven

    kanesteven

    Joined:
    Aug 30, 2018
    Posts:
    45
    @PhilSA I am not sure if this is still causing you problems but I would need to see your prediction code to know for sure. I am not seeing anything like this in my own personal project so I skeptical it's an in-built flaw.

    Regarding physics, I believe that physicshistory is recorded for any fully simulated frame and thus your prediction code is meant to request the collision world snapshot associated with the currently-predicted tick looking something like this:

    Code (CSharp):
    1. collisionHistory.GetCollisionWorldFromTick(predictingTick, interpolationDelay, out CollisionWorld world);
    The code for the Physics portion of the NetCode package is pretty small and relatively understandable so I'd suggest taking a look yourself. There are even some considerations in comments that are not written anywhere else. Perhaps @timjohansson can confirm.