Search Unity

How to config Cinemachine on a FPS

Discussion in 'Cinemachine' started by churi24, Jul 24, 2017.

  1. peruwiadomo

    peruwiadomo

    Joined:
    Jan 27, 2016
    Posts:
    14
    Another question.
    How to get forward vector from pov camera since on movement, transform its not changing an rotation. Only horizontal and vertical values on the component are going to change. Basically what I'm trying to get is vector to object that I'm looking at.

    Thanks
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,390
    If it's the active vcam, then the main Camera is tracking it, so you can use the main Camera's orientation and position. Otherwise you can use vcam.State.FinalOrientation and vcam.State.FinalPosition
     
    gatzkerob and peruwiadomo like this.
  3. peruwiadomo

    peruwiadomo

    Joined:
    Jan 27, 2016
    Posts:
    14
    Great thanks for fast reply.
     
  4. peruwiadomo

    peruwiadomo

    Joined:
    Jan 27, 2016
    Posts:
    14
    Thanks for all your help so far but sadly I have another issue.
    My camera rig have couple child vcameras with different properties like dutch or fov for different animation stages. I need to track currently active camera object to get rotation of the camera and apply it to model. If I use this code:

    Code (CSharp):
    1. child = vCamera.LiveChild as CinemachineVirtualCamera;
    2. pov = child.GetCinemachineComponent<CinemachinePOV>();
    I'm getting null but if I use a walkaround method like this:

    Code (CSharp):
    1. for (int i = 0; i < vCamera.ChildCameras.Length; i++)
    2.         {
    3.             if (vCamera.ChildCameras[i].isActiveAndEnabled)
    4.             {
    5.                 child = vCamera.ChildCameras[i] as CinemachineVirtualCamera;
    6.                 pov = child.GetCinemachineComponent<CinemachinePOV>();
    7.             }
    8.         }
    I'm introducing a new problem that all cameras can changed to state of the animation but all have different rotation. So question is how to keep all cameras in the same rotation?
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,390
    I'm having a little trouble understanding what you're asking.

    Here is what I understand so far:
    1. The model is animating (somehow)
    2. You have several cameras tracking it, from different points of view, each having a different orientation relative to the model
    3. User then re-aligns the model to something
    4. And you want all the cameras to... do what?
     
  6. peruwiadomo

    peruwiadomo

    Joined:
    Jan 27, 2016
    Posts:
    14
    Ok let me describe what exactly I'm trying to achieve.

    I have first person controller that is attached to model with animations. Next I have set of cameras with different properties like FOV, dutch, noise, and post-processing. All that is connected to animator on the model via state driven camera component to change currently active camera in the rig.

    I'm doing it like that to create different visual effects for running, standing still and so on.
    Problem is that all cameras have different rotation in the m_VerticalAxis.Value and m_HorizontalAxis.Value and you can see it when camera is changing state even if use a method like this:

    Code (CSharp):
    1. for (int i = 0; i < sdCamera.ChildCameras.Length; i++)
    2.         {
    3.             if (!sdCamera.ChildCameras[i].isActiveAndEnabled)
    4.             {
    5.                 var notActiveChild = sdCamera.ChildCameras[i] as CinemachineVirtualCamera;
    6.                 var newPov = notActiveChild.GetCinemachineComponent<CinemachinePOV>();
    7.  
    8.                 newPov.m_HorizontalAxis.Value = mainCamera.transform.rotation.eulerAngles.y;
    9.                 newPov.m_VerticalAxis.Value = mainCamera.transform.rotation.eulerAngles.x;
    10.             }
    11.         }
    With this it looks like this:



    As you can see when camera is changing state it suddenly changing rotation and going back to correct one. My mouse movement is gently left and right but you see on video how rappidly it changing orintation.

    Correct me if I'm doing it all wrong and if its a better way to do it because I stuck on this for the last week or so.
     
  7. peruwiadomo

    peruwiadomo

    Joined:
    Jan 27, 2016
    Posts:
    14
    Sorry for post after post but another issue that I have its that state driven camera not always correspond correctly to state of the animator mostly blend trees
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,390
  9. peruwiadomo

    peruwiadomo

    Joined:
    Jan 27, 2016
    Posts:
    14
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,390
    CM 2.2.8 (available now in preview) has a new feature to address exactly your problem. vcam/Transitions/InheritPosition when enabled for the FreeLook will cause the axes to be automagically aligned on transitions:

    upload_2018-10-17_17-20-17.png
     
    Last edited: Oct 18, 2018
    peruwiadomo likes this.
  11. peruwiadomo

    peruwiadomo

    Joined:
    Jan 27, 2016
    Posts:
    14
    Great. Thanks
     
  12. peruwiadomo

    peruwiadomo

    Joined:
    Jan 27, 2016
    Posts:
    14
    Is there an open github repo with this new version? My package manager showing that 2.2.7 is still up-to-date
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,390
unityunity