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

UNET Moving Platform Jitter

Discussion in 'UNet' started by TotalAnnihilation, Oct 4, 2016.

  1. TotalAnnihilation

    TotalAnnihilation

    Joined:
    May 5, 2015
    Posts:
    14
    Hello there,

    This question has been posted a few times, but only for the obsolete Unity Networking. I am currently doing a game where a player is on a moving platform and I am using UNET.
    The player gets parented to the platform which is working for all clients. Then the platform moves, and the players move with it.
    The problem: The other players jitter back and forward on each client.
    How can I solve that using UNET? The platform gets moved with through the server, the player uses a character controller and a Network Transform.
    I tried using the NetworkChildTransform, which appearently doesn't work for my setup.

    Thanks in Advance!
     
  2. Vedrit

    Vedrit

    Joined:
    Feb 8, 2013
    Posts:
    514
    On the client, are other players getting parented to the platform?
     
  3. TotalAnnihilation

    TotalAnnihilation

    Joined:
    May 5, 2015
    Posts:
    14
    Yes, they are parented.
    On the to-be-parent:
    Code (JavaScript):
    1. function OnTriggerEnter(coll: Collider){
    2.     if(!isServer)
    3.         return;
    4.     ParentPlayer(coll.gameObject);
    5. }
    6.  
    7. function ParentPlayer(player: GameObject){
    8.     if(player.tag == "Player"){
    9.         player.GetComponent(Character_Interact).RpcParent(this.GetComponent(NetworkIdentity).netId);
    10.     }
    11. }
    And on the player, with parentID being a SyncVar:
    Code (JavaScript):
    1. function Start(){
    2.     if(parentID != null){
    3.         ChangeParent(parentID);        //Applies the parent every time a new player enters the game
    4.     }
    5. }
    6.  
    7. @ClientRpc
    8. function RpcParent(id: NetworkInstanceId){
    9.         parentID = id;
    10.         ChangeParent(parentID);
    11. }
    12.  
    13. function ChangeParent(id: NetworkInstanceId){
    14.      var parentgO = ClientScene.FindLocalObject(parentID);
    15.      if(parentgO != null)
    16.          transform.SetParent(parentgO.transform);
    17. }
    And this is working, I checked it via inspector on Client and Host. The "other" Player jitters around close to the position it really is. I don't know how that comes, nor how to fix it. Thanks!
     
  4. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    How are you handling propagating the player's position to the other clients? Is Local Player Authority checked, or are you using an authoritative server approach?
     
  5. TotalAnnihilation

    TotalAnnihilation

    Joined:
    May 5, 2015
    Posts:
    14
    Thanks for your response! IsLocalPlayer is checked, the player itself is moving via root bone animation and I am using a NetworkTransform and Network Animator.
     
  6. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    Okay. Next thing to check... Your NetworkTransform, what is it synchronizing? CharacterController? Transform? Rigidbody?

    Also...the fact that you're moving the character via root bone animation may cause some issues. You're synchronizing something with the NetworkTransform, but then you're also synchronizing animation via NetworkAnimation. So the dummy character on other clients is getting information from two sources as to where it should be moving.
     
  7. TotalAnnihilation

    TotalAnnihilation

    Joined:
    May 5, 2015
    Posts:
    14
  8. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    Hmmm. Strange. It seems the issue is occurring even when the player is NOT on a moving platform. Yeah, I think you should look into the second thing I said.

    NetworkTransform is telling the dummy character where it should be. However, the Animator is also telling the character where it should be, based on the root bones animation (which it gets from the synchronized NetworkAnimator). I (THINK) the simple fix is to get rid of the NetworkTransform component, and just synchronize the Animator via the NetworkAnimator, since the Animator is controlling transform anyway.
     
  9. TotalAnnihilation

    TotalAnnihilation

    Joined:
    May 5, 2015
    Posts:
    14
    DRRosen3 - You are a genius! Such a simple solution! I don't know how much time I wasted on this, oh my...
    Thank you so much! If I can do anything for you to make it up, just let me know haha.

    Btw, I simplified the question, the players are insinde a moving spaceship, it only occurs when they are moving. I'm not quite sure what was causing the problem anyway.

    EDIT: Okay, there's another problem: Rotation doesn't get updated with NetworkAnimator, so when the player moves into a different rotation, Clients aren't syched because the NetworkAnimator only responses to the animations (I don't have an animation for rotation).
     
    Last edited: Oct 6, 2016
  10. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    Glad we got that taken care of! To sync rotation re-enable/re-attach the NetworkTransform and just set it to sync rotation. Or you can create your own scripted solution.
     
  11. TotalAnnihilation

    TotalAnnihilation

    Joined:
    May 5, 2015
    Posts:
    14
    This is working "okay". A problem occurs when local Client and the other Clients are out of sync, which happens when the animator doesn't update the position correctly. This continues and in the end, the local client is on a completly different position than on the other clients.
    Is there any way to see the NetworkTransform Script? I thought maybe syncing the localPosition would help, but you don't get to choose using the NetworkTransform haha.
    Or would you just sync it with Commands and Rpc? Thanks!
     
  12. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    I've found doing it this way seems to disable all other components on the player when re-enabling the Network Transform script.