Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Network Transform - Sync Nav Mesh agent?

Discussion in 'Multiplayer' started by Jesse_Pixelsmith, Jan 25, 2016.

  1. Jesse_Pixelsmith

    Jesse_Pixelsmith

    Joined:
    Nov 22, 2009
    Posts:
    296
    We're using UNET for multiplayer and we recently switch to try to use Unity's navmesh system for path finding for our mobs. We were having some conflicts with our mobs using navmesh agents and our players moving via CharacterController, (we have top down, WASD movement) so after doing some reading (http://angryant.com/2014/03/07/Moving-in-Unity/) - it looks like we can switch our character movement and run that by the nav mesh agent as well, which we have done and it's actually really smooth. We don't have free jumping, so there's never really a reason for the players to leave the navmesh.

    The issue now is when trying to sync over the network, where we were previously using Sync Character controller which had the advantage of velocity interpolation etc, we now it looks like have to fall back to Sync Transform which even on a LAN client is extremely stuttery.



    This is an example of our player move code given a velocity.

    void Move(Vector3 velocity)
    {
    float sqrMagnitude = new Vector2(velocity.x, velocity.z).sqrMagnitude;
    _root.Moving = (sqrMagnitude > 0 || _root.apply);
    if (!_agent.enabled)
    return;
    _agent.Move(velocity * Time.deltaTime);
    }

    Is there anything else we could be doing here? Even if the player should be controlled some other way, our AI, I imagine, should still be controlled via the navmesh agent, so we would still need to solve for that.

    Does anyone else use unity navigation and unity multiplayer (UNET)? If so how do you solve this - it's hard to find examples :)

    Thanks!
     
    lchaia likes this.
  2. cascaid

    cascaid

    Joined:
    Nov 3, 2012
    Posts:
    12
    Hi Jesse.

    The NetworkTransform component doesn't actually read any information from the CharacterController, only uses it for applying interpolation.
    Therefore you can enable the CharacterController on only the proxies, and still use the "Sync Character Controller" setting.
    This should give you the silky smooth interpolation that you're after.
     
  3. aportner_playtika

    aportner_playtika

    Joined:
    Mar 26, 2016
    Posts:
    1
    what do you mean by proxies? I'm running into the same issue. I've added a Character Controller behavior and a Nav Mesh Agent behavior. Syncing on Character Controller is very choppy for me
     
  4. sarynth

    sarynth

    Joined:
    May 16, 2017
    Posts:
    98
    Shucks, I was wondering the exact same thing.
     
  5. Bunzaga

    Bunzaga

    Joined:
    Jan 9, 2009
    Posts:
    202
    A proxy is when you use a hidden 'dummy' game object as the controlled object, and you interpolate the visible object to the proxy object.

    IE: Proxy has the nav mesh agent, and is getting the immediate update from network sync. Then a different transform, which has the model/visible stuff quickly interpolates from 'old' position to the new 'network position'.