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

How Do You Roll Back Navmesh Agent?

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

  1. gamecreatorc1

    gamecreatorc1

    Joined:
    Dec 12, 2019
    Posts:
    54
    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
  2. DJ_Design

    DJ_Design

    Joined:
    Mar 14, 2013
    Posts:
    122

    Afaik unity's navmesh is not "roll-backable" so you would have to run the pathfinding on server, or write your own pathfinding entirely to handle prediction.