Search Unity

Question How to make the camera stay behind player and face their forward direction

Discussion in 'Cinemachine' started by U_Ange, Nov 15, 2021.

  1. U_Ange

    U_Ange

    Joined:
    Nov 10, 2021
    Posts:
    5
    So I have a working free-look camera for third person, but I would like the player to be able to switch camera modes with a right mouse button, so free-look by default and then if they hold down right mouse button instead the camera looks like this:

    1:23 minute mark


    That's exactly what I'd like (camera and player always rotate the same way and always face the same direction)

    I know in this video the guy says all he did was attach the camera to the player object, but I have no idea how to do this when I already have everything for a free-look camera set up; so switching from a free-look camera to that kind of camera through code.

    I think I could just attach the camera to the Player like he did and leave it at that, and then make it so that none of the free-camera code is being executed if a player holds the right mouse button, but that sounds a bit hacky, I would much rather learn how to manually set up a camera like that through code.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    You can make a second vcam and activate it while the button is pressed.

    Make a vacm child of the player, positioned how you want it, with its Aim and Body fields set to "Do Nothing". This will create a passive vcam that is controlled by the player's transform. Then, have a script that monitors the mouse button and when it's pressed activate this vcam. If its priority is the same as or greater than the FreeLook, then CM will blend to this vcam. When the button is released, deactivate the vcam and CM will blend back to the FreeLook.
     
    yuukiandhisaxies likes this.