Search Unity

Cinemachine and Photon Pun

Discussion in 'Cinemachine' started by rubenvdweg, Mar 15, 2021.

  1. rubenvdweg

    rubenvdweg

    Joined:
    Dec 14, 2019
    Posts:
    4
    So I'm making a small multiplayer game and for the player camera's I use cinemachines.
    BUT when another player joins the scene the cameras get switched.
    Codewise everything is fine because when I don't use cinemachine it doesn't happen.
    So it has something to do with the cinemachine scripts and I'm wondering how I could change this.
    Any help/suggestions are appreciated :D
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,720
    Can you say something about how you've set up your CM cameras? How/when to they get instantiated? How do you set up the targets? What happens when a new player joins? What do you want the cameras to do?
     
    lorycontixd and nazaru3223 like this.
  3. nazaru3223

    nazaru3223

    Joined:
    Apr 2, 2021
    Posts:
    1
    Hey I have the same problem.I set up my CM cameras using unity official tutorial on YT.Target is my player I dont have any offsets.When another player joined first player camera teleports to second camera.I'm creating first person shooter and want to camera stand in the same position as in a prefab
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,720
    If you just instance a player, then nothing should happen to the camera. However, if the prefab that you instance includes a CM VirtualCamera somewhere, then that new camera will take over, unless it has lower priority than the current one. Try raising the priority of the first player's vcam after instantiating it.
     
    ArutuGaming, lorycontixd and Brodus like this.
  5. mullet12man

    mullet12man

    Joined:
    Jan 25, 2021
    Posts:
    1
    I was also having this issue. I solved it by disabling the player camera and CM camera and enabling them on Awake if PV.ismine when instantiated. This seemed to fix it.
     
    cmsngrtkn and PawaretDev like this.
  6. kalpolibrahim

    kalpolibrahim

    Joined:
    Sep 25, 2021
    Posts:
    4

    Can you simplify this i cant understand
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,720
    The Virtual Camera with the highest priority in the scene takes control of the Main Camera, always. In the event that multiple Virtual Cameras have the same highest priority, then the most-recently-created one wins.
     
    cmsngrtkn and lorycontixd like this.
  8. Player-59

    Player-59

    Joined:
    Jan 21, 2019
    Posts:
    2
    Hello Sir, I want to know whether you have a script I understand much faster in a script.

    Thank You.
     
  9. Newniverse_Interactive

    Newniverse_Interactive

    Joined:
    Jan 13, 2019
    Posts:
    10
    Don't know if it will work for you, but here is my code. I have my virtual camera as a child of my player with it being active.

    private void Awake(){

    view = GetComponent<PhotonView>();
    if (!view.IsMine && playerCamera != null)
    {
    playerCamera.SetActive(false);
    }

    }
     
    ryancat011 likes this.
  10. cmsngrtkn

    cmsngrtkn

    Joined:
    Sep 24, 2022
    Posts:
    1
    Thank you so much, you saved my life :D
     
    ryancat011 likes this.
  11. ryancat011

    ryancat011

    Joined:
    Sep 23, 2021
    Posts:
    3
    hello may I ask if you created another script (used the code that was provided) then attached it to the main camera?
    also did you disable the main camera and virtual camerafirst? thank you