Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How to change and modify z rotation value on cinemachine pov

Discussion in 'Cinemachine' started by DarkStarOffical, Feb 10, 2023.

  1. DarkStarOffical

    DarkStarOffical

    Joined:
    Oct 25, 2020
    Posts:
    7
    Hi, how can i change z rotation value because i cant from inspector. i can change x and y values from code via
    m_HorizontalAxis.Value and m_VerticalAxis.Value but i dont know how to change z value.
    Thanks
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,267
    To change the Z rotation you can adjust vcam.m_Lens.Dutch:

    upload_2023-2-10_7-7-26.png
     
  3. DarkStarOffical

    DarkStarOffical

    Joined:
    Oct 25, 2020
    Posts:
    7
    Thanks for feedback but the thing is i have headbob animation made by Dutch value. like that gameobject which contains virtual camera has animator which contains headbob animations and i think they will cause conflict. idea is that when i press certain button camera should lean. so like when we hold Q that gameobject which contains virtual camera should take rotation and position of the leaned gameobject. i know that i should use lerp function but i cant really think how can i do it. Thanks
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,267
    You would have to make a custom CM extension that adds Dutch to the vcam's lens at the end of the pipeline. You can use CinemachineCameraOffset.cs file as a starting point. Copy and rename it, and add it to your project. Modify the code to change state.Lens.Dutch instead of state.RawPosition.
     
  5. lecramr

    lecramr

    Joined:
    Jun 22, 2023
    Posts:
    7
    Hello @Gregoryl I am running into the same problem, I don't want to use the Dutch Property as I currently animate the Camera via a tweening Library, which also tweens the rotation, this is working great for x and y axis, but as pointed out not for z. To not introduce complexity to the tweening process, as it's already complicated. I would like to add the extension you described. Currently it's not working as expected, I attached what I got so far (not much). Could you maybe help me?


    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. [AddComponentMenu("")]
    5. [ExecuteAlways]
    6. [SaveDuringPlay]
    7. public class CinemachineZToDutch : CinemachineExtension
    8. {
    9.     public CinemachineCore.Stage m_ApplyAfter = CinemachineCore.Stage.Aim;
    10.  
    11.     protected override void PostPipelineStageCallback(
    12.         CinemachineVirtualCameraBase vcam,
    13.         CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    14.     {
    15.         if (stage == m_ApplyAfter)
    16.         {
    17.             state.Lens.Dutch = state.RawOrientation.eulerAngles.z;
    18.         }
    19.     }
    20. }
    21.  
    Looks like state.RawOrientation.eulerAngles.z is having somekind of maybe right values, but Dutch is not getting applied.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,267
    If you are animating the camera via a tweening library and are also using Cinemachine, they will fight as they are both trying to animate the same thing. CM needs to have complete control over the camera.

    Maybe you can describe your use-case a little more fully. What are you expecting CM to do for you if you're already animating the camera by other means?
     
  7. lecramr

    lecramr

    Joined:
    Jun 22, 2023
    Posts:
    7
    Sure! We already had a small chat before I went on vacation.
    The requirements are to have a Virtual TV Studio. This Studio should have 12 different Camera Angles, with click of a Button the Camera should "fly" to another Position, as smoothly as possible. This of course it totally achievable with the cinemachine. The problems why I choose to go the tweening route are, first the user should be able to stop the transition mid flight, so slowly ease out the movement and keep the camera steady and the continue it again, I was not able to implement it good enough. But the biggest issue is that the user should be able to change the position midtransition, and the camera would change to the new position via a bezier curve, to ease out the movement. The problem the cinemachine had is, that it eased out stopped the camera and then ease in and started the animation to the different position.

    So my solution is currently, to create a tracked dolly path, which is either direct to the other position, or in case the user interrupted mid-transition it creates a bezier path to ease out. And I "only" animate the position on the dolly path via a tweening library and also the rotation. As the Camera Positions could either be "look at" or "free looking" cameras. I hope I explained it weill enough!
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,267
    I think a much simpler and more direct approach would be to create an invisible GameObject and animate that however you like. Then, use that object as a Follow target (with 0, 0, 0 as target offset) for the vcam, and adjust the damping in the Transposer until the smoothness is how you like it.
     
  9. lecramr

    lecramr

    Joined:
    Jun 22, 2023
    Posts:
    7
    That could also maybe work, the problem is that the Bezier Curves from DOTween and so the animation, is looking way worse that doing the animation via the tracked dolly in the cinemachine.
    But I would also gladly completly use the cinemachine, are the problems I outlined above somehow "solveable" with a cinemachine only solution?
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,267
    I think this is completely achievable in CM3, which has improved transition logic compared to CM2.x. With CM3, when you interrupt a transition in progress the results are smooth, because under the hood it does (A->B)->C, and (A->B) completes while transitioning to C, resulting in a smooth curve. You should be able to get what you want out of the box, with no splines.

    https://forum.unity.com/threads/new-version-of-cinemachine-3-pre-release-9-is-now-available.1501472/

    If you would like to create a little mock-up test project to experiment with the cameras, you can share that with me and I can help solve any problems.
     
  11. lecramr

    lecramr

    Joined:
    Jun 22, 2023
    Posts:
    7
    Thank you really really much for your help and ideas!
    I just implemented your FollowTarget Ideas as a Test and it seems to work exactly as I expect it to behave! But for the future I want to to test and maybe update it to the cinemachine (only). Do you know when the version 3 eta is, as it's a customer project and I want to implement only production ready code?
     
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,267
    CM3 will be released officially with Unity 2023.2.
     
    lecramr and Lurking-Ninja like this.