Search Unity

Mix user input result to control the camera with existing look at results.

Discussion in 'Cinemachine' started by JadeEmpire, Jan 7, 2019.

  1. JadeEmpire

    JadeEmpire

    Joined:
    Oct 26, 2016
    Posts:
    14
    I want to setup vcams with look at targets as normal using composer etc. But I need the camera to be also tweaked by a cinematographer at the end.

    The cinematographer is using a mouse to adjust the position and rotation of a vcam in realtime, based on how he likes cinemachine's composition. So its: cinematographer's final tweak + procedural composition by out-of-the-box components.

    I looked through all the classes and such, the only thing close to it is the mixingcamera that takes an average?? I need the cinematographer's input be definite and has the final say on the final composition.

    I created a new class, inheriting virtualcamerabase. It just sums all of its children's pos and rots together. Is this the correct way to do it? or something else you'd recommend?

    Secondly, currently my design is:
    outside monobehaviour input class that takes a virtual camera prefab, expecting donothing components on it, and this class can set the vcam's position only or rotation only or both.
    when I set up the scene, I just need to make sure the I put all vcams under my virtual camera class, which sums together its children's rot and pos.
    Please let me know if this whole setup is on the right direction, or should I not control donothing cameras in this case, but instead create 2 new virtual camera components?

    Thanks so much!!!
     
    Last edited: Jan 7, 2019
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,501
    Sounds like overkill to me. If it's a vcam looking at something and you want to adjust the target's screen position with the mouse, why not simply map the mouse's movement to an adjustment of the composer's ScreenX and ScreenY fields? You can do this with a script attached to the vcam.
     
  3. JadeEmpire

    JadeEmpire

    Joined:
    Oct 26, 2016
    Posts:
    14
    sometimes I have the damping too high so the cinematographers('dp') input may not have the expected effect. the DP's input has to be definite

    I just had a monobehaviour singleton camera controller class calculates the direction, and the distance, and it expects a serializefield vcam gameobject prefab to use. It then uses those data that to animate the donothing camera. it has a very simple damping threshold, as mentioned. I may end up try both because your solution sounds much more integrated within the pipeline.

    However, now I also want the DP to automatically have the ability to influence the current active vcam.

    I''m thinking the design would be: in editor, I have to make everything a child of the sumvcam.cs I created myself.(combines all of its children's position data, a bit different from the default CM mixingcamera which calculates an average) It also must have a donothing camera in the children gameobject list....(i know............)

    runtime: the monobehaviour input singleton class listens to m_CameraActivatedEvent, and get the active camera, validate that it has a sumvcam.cs as parent and a donothing, then takes that donothing and animate it?

    would this be the best way in the current scenario? also for your approach, I think I just need to make the script that attaches to the brain, listens to the event as described, and gets the active vcam, adjusts its screenX and Y?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,501
    Here's another option: create a custom CinemachineExtension that adds a rotation delta (provided by the DP) to the vcam's orientation. Simple and sweet, and only a few lines of code.

    You can just put that extension on all your vcams. No events, no mess.
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,501
    Here is some code to do that. Drop it onto your project, and it will be available in the extensions dropdown in the vcam inspector. You now just need to add some code to allow the DP to manipulate the m_Offset field (you can add an Update() method for that).
    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. /// <summary>
    5. /// An add-on module for Cinemachine Virtual Camera that adds a final offset to the camera
    6. /// </summary>
    7. [AddComponentMenu("")] // Hide in menu
    8. public class CinemachineAimOffset : CinemachineExtension
    9. {
    10.     [Tooltip("Offset the camera's aim by this much")]
    11.     public Vector3 m_Offset = Vector3.zero;
    12.  
    13.     protected override void PostPipelineStageCallback(
    14.         CinemachineVirtualCameraBase vcam,
    15.         CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    16.     {
    17.         // Apply after the camera has been aimed.
    18.         if (stage == CinemachineCore.Stage.Aim)
    19.         {
    20.             Quaternion offset = Quaternion.Euler(m_Offset);
    21.             state.OrientationCorrection = state.OrientationCorrection * offset;
    22.         }
    23.     }
    24. }
    25.