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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

NetworkTransform jerky movement 3D

Discussion in 'Multiplayer' started by Bobby-Marley, May 23, 2015.

  1. Bobby-Marley

    Bobby-Marley

    Joined:
    May 23, 2015
    Posts:
    2
    Hi there
    Im using Unity 5.1 and playing around new UNET api. Made a simple 3D multiplayer testing game that is made with NetworkTransform. Syncing only player transforms, it works, but their movement is VERY jerky. Is there any way to smooth it? I've been using Lerp for this purpose on older versions of Unity. Don't really want to write all player sync scripts manually.
    Spent a long time walking around Interpolation, Threshold and other stuff, but nothing changed...


    Please help...
     
  2. Puhree

    Puhree

    Joined:
    Sep 3, 2014
    Posts:
    3
    If you're using rigidbodies for players then try using the Sync Mode: Rigidbody 3D. changing that to transform mode causes visual lag. Remember that rigidbody-based movement requires networking physics which is a formidable task (even if you're moving your players in a kinetic manner). So sending only transform means sending zero information about angular/linear velocity which is crucial in networking physics based objects. I hope i didn't say anything stupid.
     
    Azurne likes this.
  3. Bobby-Marley

    Bobby-Marley

    Joined:
    May 23, 2015
    Posts:
    2
    Switched to rigidbody3d sync, played with those threshold, interpolation and etc. but movements are still jerky...
     
  4. Acegikmo

    Acegikmo

    Joined:
    Jun 23, 2011
    Posts:
    1,293
    For what it's worth - I'm having the very same issue, running 5.1.1p3
     
  5. PatrikL

    PatrikL

    Joined:
    May 11, 2014
    Posts:
    6
    I think you might be missing the [Command] part of this.

    Look at the example script below, although I'm hardly an expert (Just got started myself). Using this script will cause the local player input to be sent as commands. This means that the actual input and movement are happening on both server and clients. And I guess the NetworkTransform keeps things synced up good between its syncing intervals.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Networking;
    4. using UnityStandardAssets.CrossPlatformInput;
    5.  
    6. public class PlayerController : NetworkBehaviour
    7. {
    8.     float moveX = 0;
    9.     float moveY = 0;
    10.     float moveSpeed = 0.2f;
    11.  
    12.     void Update ()
    13.     {
    14.         if (!isLocalPlayer) {
    15.             return;
    16.         }
    17.        
    18.         // input handling for local player only
    19.         float oldMoveX = moveX;
    20.         float oldMoveY = moveY;
    21.  
    22.         moveX = CrossPlatformInputManager.GetAxis ("Horizontal");
    23.         moveY = CrossPlatformInputManager.GetAxis ("Vertical");
    24.  
    25.         if (moveX != oldMoveX || moveY != oldMoveY) {
    26.             CmdMove (moveX, moveY);
    27.         }
    28.     }
    29.  
    30.     [Command]
    31.     public void CmdMove (float x, float y)
    32.     {
    33.         moveX = x;
    34.         moveY = y;
    35.     }
    36.    
    37.     public void FixedUpdate ()
    38.     {
    39.         transform.Translate (moveX * moveSpeed, moveY * moveSpeed, 0);
    40.     }
    41. }
     
  6. Deleted User

    Deleted User

    Guest

    The is no interpolation or any lerping for syncing the transform, as far as i know. But you can easily make your own transform sync script.
     
  7. Chris-Crafty

    Chris-Crafty

    Joined:
    May 7, 2013
    Posts:
    27
    Question: What is the reason for an "API provider" like Unity to "provide" something that is unusable in actual production environments like, I don't know, "games", because it hasn't even basic functionality implemented? I mean, I checked the "NetworkStarter" sample from http://forum.unity3d.com/threads/unet-sample-projects.331978/#post-2216484 , and even on the same machine, movement of the 3 (in words: three) boxes on the client was jerky as hell. So unless somebody messed up with the simulation parameters for network package loss, the network position sync is simply unusable unless you have a turn-based game with no animation at all.

    And frankly, if I "can" implement everything myself, why bother using an "out of the box solution" in the first place?
     
  8. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    836
    GTGD goes over a custom lerping for syncing transforms in his first part of his tutorial, here.