Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Resolved Virtual Cameras Maintain Rotation when Inactive

Discussion in 'Cinemachine' started by wingeman012, Jan 19, 2021.

  1. wingeman012

    wingeman012

    Joined:
    Dec 30, 2020
    Posts:
    2
    Hello,
    I am just getting started with Unity and Cinemachine. I'm working on some basic prototypes to understand system functionality and have been browsing the forums to address questions as they arise. I seem to have hit a roadblock I'm not quite sure how to get over though.

    I have 2 virtual cameras in my scene: a freelook camera and a third person follow (over-the-shoulder). The way I want it to work (which it does) is that the freelook camera is default and it switches to the shoulder camera when the player holds the "Target" button (Tab or L1). The issue I'm having is that each camera maintains its rotation while the other camera is active. So when I switch cameras, the camera snaps to its last active rotation. What I want is for the camera to default behind player when the camera switches active.

    In the sample image below: there are three objects in the scene: sphere, cube, and cylinder in addition to the red player model. Game starts, user moves the player model and freelook camera to face the sphere. User presses the Target button, shoulder cam becomes active. Because the shoulder cam was originally set up to look in the global Z=0 direction (we'll call it North), the camera instantly snaps to looking North. Because of the way player movement is handled while in shoulder cam mode, player model snaps to face North as well. The user then rotates the player model to face cube. When user releases the target button, player model will still be facing cube but the freelook camera will be back to looking at the sphere. Now, user rotates player model to look at the cylinder. When player presses the Target key again, shoulder cam and player model snap to look at cube again.
    upload_2021-1-19_8-36-48.png

    I'm thinking this can be resolved by either having the cameras continue to receive mouse/joystick input even when inactive (although this seems inefficient and I would probably need to have CameraManager change the Shoulder cam priority when the target key is active rather than making cameras active/inactive) or to have the cameras default to a position behind the player model when isActive switches true.

    Any ideas how to accomplish either of these? I've attached a unitypackage with my setup for reference so you can see the scripts I'm using and my camera settings. I'm running Unity 2019.4.18f1, Cinemachine 2.6.3, and Input System 1.0.1.

    Let me know if you need any more info and thanks in advance for the help!
     

    Attached Files:

  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,238
    Enable this:

    upload_2021-1-19_9-16-9.png
     
  3. wingeman012

    wingeman012

    Joined:
    Dec 30, 2020
    Posts:
    2
    Wow, so simple. Can't believe didn't figure that one out on my own.. Thanks a lot!
     
    Gregoryl likes this.