Search Unity

Resolved World Up gets ignored on my Virtual Camera

Discussion in 'Cinemachine' started by flow-, Jan 28, 2021.

  1. flow-

    flow-

    Joined:
    Apr 19, 2015
    Posts:
    171
    Hey, I recently switched the Camera from the Free Look to the Virtual Camera Component as I would like to add Offset and collisions and set up for the Body the Framing Transposer and for the Aim the POV component... I experienced a bug while testing the controller on Faux Gravity where the World Up which is set in the Cinemachine Brain to the character but gets ignored with this special setup... I've tested some other components and the Composer Component in the Aim would work but would not allow me to have Input Axis to control the camera.
    Here where I am now:



    And here what I like to archive with this World Up:



    My Virtual Camera looks like this:
    Screenshot from 2021-01-28 05-16-12.png
    Screenshot from 2021-01-28 05-17-03.png

    And that's the cinemachine brain component:
    Screenshot from 2021-01-28 05-18-21.png


    Did I miss something?
    Would be lucky to have some help :)
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    5,494
    POV applies the pan and tilt relative to the vcam's parent object - which is worldspace if no parent. Try parenting your vcam to an empty GameObject and adjust that object's rotation to define world up.
     
    flow- likes this.
  3. flow-

    flow-

    Joined:
    Apr 19, 2015
    Posts:
    171
    Thanks, I did that, it took me some hours to figure out the needed rotation to keep the global Y Axis under control at zero as I experienced ( which is just my setup of the character ) that the character depends on the rotation of the vcam which I changed when making the rotation...
    But finally, I was able to produce a perfect rotation :)

    I also would like to share the script I use:

    Code (CSharp):
    1. using Cinemachine;
    2.     using UnityEngine;
    3.    
    4.     public class CinemachineWorldUpPOV : CinemachineExtension
    5.     {
    6.         public enum RotationType
    7.         {
    8.             SIMPLE_ROTATE,
    9.             KEEP_Y
    10.         }
    11.  
    12.         [SerializeField] protected RotationType _rotationType = RotationType.KEEP_Y;
    13.         [SerializeField, Range(0f, 10f)] protected float _rotationSpeed = 3f;
    14.         [SerializeField] protected bool _instandRotation = false;
    15.  
    16.         private Transform _root;
    17.         protected bool valid;
    18.  
    19.         protected virtual void Start()
    20.         {
    21.             _root = this.transform.root;
    22.  
    23.             if (_root == this.transform || _root == null) { Debug.Log("The POV Component need to have an parent Transform, in order to produce an relative UP Rotation.... Please make the Virtual Camera A child of a GameObject..."); valid = false; return; }
    24.  
    25.             valid = true;
    26.         }
    27.  
    28.  
    29.         protected override void PostPipelineStageCallback(CinemachineVirtualCameraBase vcam, CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    30.         {
    31.             if (!valid) return;
    32.             if (deltaTime == 0f) return;
    33.  
    34.             // GETTING THE WORLD UP ROTATION
    35.             Quaternion UpRotationForward = Quaternion.LookRotation(state.ReferenceUp.normalized) * Quaternion.Euler(Vector3.right * 90f);
    36.             if (_rotationType == RotationType.KEEP_Y)
    37.             {
    38.                 Quaternion wantedRotationRelative = Quaternion.Inverse(UpRotationForward) * _root.rotation;
    39.  
    40.                 Vector3 euler = wantedRotationRelative.eulerAngles;
    41.                 euler.x = euler.z = 0f;
    42.  
    43.                 Quaternion wantedFinal = UpRotationForward * Quaternion.Euler(euler);
    44.  
    45.                 _root.rotation = _instandRotation ? wantedFinal : Quaternion.Lerp(_root.rotation, wantedFinal, deltaTime * _rotationSpeed);
    46.             }
    47.             else if (_rotationType == RotationType.SIMPLE_ROTATE)
    48.             {
    49.                 _root.rotation = UpRotationForward;
    50.             }
    51.         }
    52.     }
    Maybe I help someone in future with it
     
    Gregoryl likes this.
unityunity