Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Best way to combine POV controls with an animated lookat

Discussion in 'Cinemachine' started by melting_pot, Jan 23, 2019.

  1. melting_pot

    melting_pot

    Joined:
    Mar 2, 2018
    Posts:
    9
    Hi, I'm wondering what is the best way to have a vcam following a moving object, but to also allow user input to offset the view direction by a few degrees? I want to be able to look around the object and then snap back to the object when there's no input.

    Currently using a standard composer to follow the lookat object, but not sure on the best way to add the user control on top. POV is close but doesn't quite do what I want as I can't seem to make it follow a lookat object.

    RIght now I'm thinking the best option is to add an extension similar to CinemachineCameraOffset and use that on top of a composer.

    Any ideas? Thanks!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    The extension idea is the way to go. You can basically take what CinemachinePOV.cs does and repackage it as an extension: after the Aim stage, add state.OrientationCorrection in response to the H and V axes. That will give you exactly what you're looking for.

    Feel free to post the new extension here once you get it working, or beforehand if you need some help with it.
     
  3. melting_pot

    melting_pot

    Joined:
    Mar 2, 2018
    Posts:
    9
    Thanks - that's exactly what I needed. Snapping back to the lookat target just worked automatically as well, which was perfect.

    This is the very simple extension I ended up with:

    Code (CSharp):
    1.     protected override void PostPipelineStageCallback(
    2.         CinemachineVirtualCameraBase vcam,
    3.         CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    4.     {
    5.         // Apply after the camera has been aimed.
    6.         // To apply offset before the camera aims, change this to Body
    7.         if (stage == CinemachineCore.Stage.Aim)
    8.         {
    9.             // vVal and hVal are derived from user touch/mouse screen position
    10.             state.OrientationCorrection = Quaternion.Euler (hVal,vVal,0f);
    11.         }
    12.     }
     
    Gregoryl likes this.