Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Help with multiplayer cameras

Discussion in 'Multiplayer' started by bman610110, Dec 27, 2023.

  1. bman610110

    bman610110

    Joined:
    Feb 16, 2021
    Posts:
    1
    Hello I am newly learning Unity Netcode. For my game I have the camera detached from the player object with a follow script. Of course this doesnt work with multiple players as the camera is stolen by the most recent joiner. Its probaly something im overlooking or am not knowledglable enough about yet but im wondering if there is a way of having the camera only affected by the local player and how I would go about doing this. Below is my code and a small video demoing the issue.

    Camera Follow:
    Code (CSharp):
    1. void Update()
    2.     {
    3.         if(GameObject.FindObjectOfType<PlayerMovement>() != null) player = GameObject.FindObjectOfType<PlayerMovement>().gameObject;
    4.         if(player != null) transform.position = new Vector3(player.transform.position.x, player.transform.position.y, this.transform.position.z);
    5.     }
    Issue Video:


    Alternitivly if there is a way where i can have the camera on the player and have the player point towards the mouse without spinning the camera that would be appreciated. :) Thank you very much for your time!