Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Client Side network transform problem

Discussion in 'Connected Games' started by noobgag, Nov 1, 2018.

  1. noobgag

    noobgag

    Joined:
    Jan 26, 2018
    Posts:
    6
    The black box (has its own network transform)snipping up and down was supposed to follow the player with a fixed offset and works perfectly in the host side but it keeps snipping up and down in the client side even the black box was not supposed to be moving as the playing is not moving.

    The video:
    https://drive.google.com/file/d/1Bm-lm9YINo00uNl8MF0msSJ1Jr7hc36l/view?usp=sharing

    The script :


    using UnityEngine;

    public class CameraFollow : MonoBehaviour {

    public Transform player;
    Vector3 offset = new Vector3(1,1,0);

    // Update is called once per frame
    void LateUpdate () {
    if(player !=null)
    {
    transform.position = player.position +offset;
    }
    }
    }
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,832
    Is this the correct script? This script doesn't have anything network related. It just sets its position to an offset of whatever the player position is, so if it is moving unexpectedly your problem is going to be on whatever object is assigned to the player variable.

    Also, you're not going to get many people downloading files from your google drive to help with a forum question.
     
  3. noobgag

    noobgag

    Joined:
    Jan 26, 2018
    Posts:
    6
    Thx for the replay, I thought people can view the video online without downloading it , I will upload it on youtube later.
    The player variable is assigned to the black box when it is spawned and I assigned a network transform component to the black box prefab to keep track of its movement

    The following script are in the player manager script which is assigned to the player prefab

    void Start()
    {
    CmdSpawnMissile();
    }
    [Command]
    void CmdSpawnMissile()
    {
    missile = Instantiate(missilePreFab,transform.position+ offset,transform.rotation);
    missile.GetComponent<MissileMovement>().SetUpFromSpawn(this);
    missile.GetComponent<CameraFollow>().player = GetComponent<Rigidbody>().transform;
    NetworkServer.Spawn(missile.gameObject);
    }
     
  4. noobgag

    noobgag

    Joined:
    Jan 26, 2018
    Posts:
    6
  5. noobgag

    noobgag

    Joined:
    Jan 26, 2018
    Posts:
    6
    The missile movement script controlls the black box movement after it is fired so should not casue the problem as I havenot added the fire() method into the player controll yet.
     
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,832
    Your Start in the player management script is going to try to call CmdSpawnMissile() on the host and every client individually. It is going to fail on most clients and give a warning regarding lack of authority to run the command, but you should still specify what machine you want to run that command from instead of running it on all machines.

    So the black box is the missile? Where on the clients are you setting CameraFollow.player? You've only shown where you are setting that on the server. Are you getting null reference errors on the clients?
     
  7. noobgag

    noobgag

    Joined:
    Jan 26, 2018
    Posts:
    6
    Yes the black box is the missile, there is no null reference error on the client, the black box are able to follow the player on the client side but there is still the problem of snipping up and down even when it is following the player and when the blakc box is not supposed to be moving
     
  8. noobgag

    noobgag

    Joined:
    Jan 26, 2018
    Posts:
    6
    Could anyone help me with this please