Search Unity

Need help, setting up a 3rd person rotatable camera.

Discussion in 'Multiplayer' started by FoxCastz, Jun 18, 2015.

  1. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    So I have a working version of a 3rd person rotatable camera in single player, but with multiplayer its a different story. The issue I am having is that I need to Initialize a Camera and somehow link it to a freshly initialized player. Since both are freshly initialized I have no clue how to link them together in the unity editors, whereas in single player, both the player and the camera exist before the game is even run, thus allowing pre-linked setups.

    This is how I have attempted to tackle the problem. Once the spawnPlayer() method is run, a player will spawn properly and on that player is a ClickToMove script which runs the following:

    public GameObject linkCamera; //This is empty and links to cameraPrefab on instantiation.
    public GameObject cameraPrefab; //This has the prefab of the camera.
    public Transform cameraPos;

    void Awake(){
    cameraPos = GetComponent<Transform> ();
    cameraPos.position.Set(cameraPos.position.x - 3f, cameraPos.position.y + 3.6f, cameraPos.position.z - 3f);
    linkCamera = (Network.Instantiate(cameraPrefab, cameraPos.position, Quaternion.identity,0) as GameObject);
    linkCamera.GetComponent<CameraFollow> ().target = GetComponent<Transform>();
    }
     
  2. powdered_swords

    powdered_swords

    Joined:
    Mar 11, 2013
    Posts:
    28
    Is there any reason why the camera needs to be instantiated over the network? If not you could just load the camera prefab locally.
     
  3. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    That sorta of works, but now I have the issue of when a second player joins, the controls for the first players are suddenly switched and the second camera is instantiated by the newest players feet.
     
  4. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    It also appears that the second camera will not follow the newly spawned player.

    I've tried these to remedy the switched movement issue:
    if (!GetComponent<NetworkView> ().isMine) {
    enabled = false;
    }
    and

    if (GetComponent<NetworkView> ().isMine) {
    //Move the player to the position
    moveToPosition ();
    }
     
  5. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    anywahn? :(
     
  6. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    Nvm I figured it out. Thank you.
     
  7. sethHarrison

    sethHarrison

    Joined:
    Sep 18, 2014
    Posts:
    1
    How'd you figure it out? I'm having this problem just as you describe it here, "issue of when a second player joins, the controls for the first players are suddenly switched and the second camera is instantiated by the newest players feet."

    Update! Aha, I fixed my issue too. I was being lazy and telling the camera to follow the tag: player. I suppose it was just finding the first object with that tag and following it, but all of my players have the player tag so that was rubbish. Once I properly identified each instantiated player the issue was fixed.
     
    Last edited: Jun 29, 2015