Search Unity

Question Cinemachine switch players

Discussion in 'Cinemachine' started by dreeanx, Mar 27, 2023.

  1. dreeanx

    dreeanx

    Joined:
    Mar 27, 2023
    Posts:
    3
    Hey, I'm developing a game in which I'm able to switch between two characters by pressing x ( like in cuphead but it's the characters that swap and not the weapons )

    I'm using the cinemachine component for my camera but I can't get my camera to follow the second character once I press x as there is only one target slot, and I've searched and searched but I can't find a script that can fix my problem. Can you help me?
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Create two VirtualCameras. One following player1 and one following player2. When you switch between players, you switch VirtualCameras.

    CinemachineBrain selects the active VirtualCamera with highest priority or if priorities are the same then the most recently activated VirtualCamera.
    So in your case:
    When you'd like player1 to be followed, then player1VirtualCamera is actived and player2VirtualCamera deactived.
    When you'd like player2 to be followed, then player2VirtualCamera is actived and player1VirtualCamera deactived.
     
  3. dreeanx

    dreeanx

    Joined:
    Mar 27, 2023
    Posts:
    3
    yes i tried that but the camera on my player2 stays on standby all the time even when the player is activated so the active camera stays the camera on player1 all the time
     
  4. dreeanx

    dreeanx

    Joined:
    Mar 27, 2023
    Posts:
    3
    nevermind haha i fixed it thxxx
     
    antoinecharton likes this.