Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How Do You Roll Back Navmesh Agent?

Discussion in 'Multiplayer' started by gamecreatorc1, Apr 6, 2021.

  1. gamecreatorc1


    Dec 12, 2019
    I'm relatively new to Unity (but have other programming experience). I'm implementing Host/Client multiplayer but I'm not sure how I would go about rolling back a navmesh agent.

    The idea is that the host and client are synced but say there's lag and the client's packets are delayed. As such, once the host receives the packets, it has to roll back the simulation to make sure everything was predicted correctly, including any new surprise collisions that may push things off the predicted course.

    And this is where I'm not sure how to proceed.

    I can put the agent back to the location and rotation it was at during the last valid frame. Maybe even apply the known velocity. But then what?

    There's a CalculatePath function but that only provides waypoints. Even if it gave you a complete list of points at the desired frames per second, that wouldn't include any possible collisions along the way.

    The other thought is simply to reapply SetDestination but then how do I move the simulation forward several frames to catch up. Do I need to manually run physics/AI simulations?

    What's the correct way to do this? Or is it even possible?

    Note: I'm using the AI off of GitHub because my world is procedurally generated.
    Last edited: Apr 6, 2021