Search Unity

Question How to make two cameras: with world up override, and without world up override?

Discussion in 'Cinemachine' started by DrViJ, Aug 19, 2020.

  1. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    163
    I see that world up override is inside cinemachine brain. But I have two camera behaviours.

    • One is topdown camera with a small yaw (around world Z axis) and looking at target. it has world up override.
    • The second one should not have a world up override. it looks forward and can yaw too(around world y axis)
    I want to blend between theese cameras. If I use World Up Override - First camera works weird cause I am looking topdown (it starts rotating 180)
    If I dont use World Up Override - Second camera works weird.

    So how to have two cameras with and withoun World Up Override? How to blend between such cameras?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    You can try making a custom extension for the vcam that needs a custom up override. Just set the state.ReferenceUp in the Body stage of the PostPipelineStageCallback.
     
    DrViJ likes this.
  3. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    163
    Thats great, just what I need. Thank you!
     
  4. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    120
    this doesn't seem to work with a FreeLook vCam.


    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. public class CinemachineCustomCameraUp : CinemachineExtension
    5. {
    6.     private Vector3 _up;
    7.      
    8.     public void SetUpDirection(Vector3 up) => _up = up;
    9.  
    10.     protected override void PostPipelineStageCallback(
    11.         CinemachineVirtualCameraBase vcam,
    12.         CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    13.     {
    14.         if (stage == CinemachineCore.Stage.Body)
    15.         {
    16.             state.ReferenceUp = _up;
    17.         }
    18.     }
    19. }
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    It should work. Can you show the FreeLook inspector?
     
  6. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    120
    thanks for replying so quickly even though i took so long to notice it!
    i'm seeing different behavior between the override you can assign via the brain inspector and override done in the script like above. this is with CM 2.9.0-pre.6 and Unity 2023.1.0a17. i zipped up the scripts, scene, and materials (URP) if you want to drop this into a project and try it yourself. it may be worth observing this in the scene view as well - the freelook doesn't follow the rig gizmos for some of the binding modes when overriding the up direction via script. besides testing different binding modes and adjusting the orbit size of each rig slightly, the inspector for this freelook was default values.

     

    Attached Files:

    Last edited: Jan 29, 2023
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Nice repro scene!

    The problem is your OverrideWorldUp script. It should be this:
    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. public class CinemachineOverrideWorldUp : CinemachineExtension
    5. {
    6.     public Transform up;
    7.     public override void PrePipelineMutateCameraStateCallback(
    8.         CinemachineVirtualCameraBase vcam, ref CameraState state, float deltaTime)
    9.     {
    10.         if (up != null)
    11.             state.ReferenceUp = up.up;
    12.     }
    13.  
    14.     protected override void PostPipelineStageCallback(
    15.         CinemachineVirtualCameraBase vcam,
    16.         CinemachineCore.Stage stage, ref CameraState state, float deltaTime) {}
    17. }
    18.  
     
    Whatever560 and owen_proto like this.
  8. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    120