Search Unity

Some Question regarding camera

Discussion in 'Cinemachine' started by witcher101, May 22, 2018.

  1. witcher101

    witcher101

    Joined:
    Sep 9, 2015
    Posts:
    516
    I am working on a side scroller game and am currently using a sidescroller camera drive by scripts.
    I have created a cutscene virtual camera.Now when i start the game my current camera is displaying cutscene area. I even disabled playonawake in timeline. I want camera to only go to virtual camera when i trigger cutscene.
    So do i need to enable and disable virtual cameras for cutscene??
    Also how do i determine that a cutscene has finished
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    The CinemachineBrain on the Camera is expecting to be driven by a virtual camera, and it's using the one from the cutscene because that's what it can find.

    The simplest thing for you to do would be to convert the script-driven camera to a virtual camera. Replace the Camera component in your script-driven camera object with a VirtualCamera that has Do Nothing in both the Aim and the Body sections. That will allow its transform to be driven by your script. Give it a higher priority than the cutscene cameras and it will become the default game camera. Then, when the timeline kicks in, the camera will blend to the cutscene vcam, and when the timeline ends, it will blend back automatically.

    You would know that the cutscene has finished when your GamePlayCamera becomes activated again. You can either poll it, or listen to the Brain's OnCameraActivated event.

    Your hierarchy would look something like this:

    Main Camera game object
    - Camera component

    GamePlayCamera game object
    - CinemachineVirtualCamera component (with Do Nothing in Aim and Body)
    - your custom scripts implementing the side-scrolling behaviour

    CutsceneCamera 1 game object
    - CinemachineVirtualCamera component (with lower priority)

    etc
     
  3. witcher101

    witcher101

    Joined:
    Sep 9, 2015
    Posts:
    516
    Thanks this work. But
    I need something better than OnCameraActivated, since i need to call an event after cutscene has ended and i cant use OnCameraActivated since it will be different for different cutscenes
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    When your cutscenes end, don't they all return control to the game camera? So a notification that the game camera is being activated is a good way to know that the cutscene is ending, right? Am I missing something?
     
  5. witcher101

    witcher101

    Joined:
    Sep 9, 2015
    Posts:
    516
    Lets say i have 2 cutscenes. After 1st cutscene ends i wana spawn enemies and after 2nd cutscene ends i dont want to spawn enemies. So if i call spawn after OnCameraActivated it will spawn enemies after both cutscenes
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    So you need to keep track of some kind of state so that you know what to do. Your handler would look at that state.