Search Unity

Cinemachine FreeLook with Zoom Sluggish

Discussion in 'Cinemachine' started by Zyrathius, Apr 4, 2019.

  1. Zyrathius

    Zyrathius

    Joined:
    Dec 18, 2012
    Posts:
    20
    Hey Guys, I have tried to cobble together the code bits shared on another thread on adding mouse wheel zooming with FreeLook Camera rig. In addition, my rotation only works when the mouse button is pressed.

    Everything works for the most part, however I notice when I use the mouse wheel for zooming, it seems to be sluggish when changing directions. To be more specific, if I advance the wheel one notch/click at a time, when I go the other direction, the first notch/click still goes in the old direction before the 2nd notch/click works properly. It's as if the Z Axis Value being used is one frame behind or something when updating it's axis direction. When running you can see the Value rising with each mouse wheel rotation and the instant you reverse mouse wheel rotation, the value continues to rise one more time before it begins to actually reverse the value and decrease. Hopefully this makes sense. All in all, it just feels sloppy and slightly confusing when users go from zooming in to out or vice versa.

    Any advice appreciated, I've been trying to figure it out for a few days now and it all looks the same at this point.

    I believe these are the relevant code bits I'm using.


    Code (CSharp):
    1.         private void Start()
    2.         {
    3.             CinemachineCore.GetInputAxis = GetInputAxisCustom;
    4.         }
    5.  
    6.         void Awake()
    7.         {
    8.             freelook = GetComponentInChildren<CinemachineFreeLook>();
    9.         }
    10.  
    11.  
    12.         void Update()
    13.         {
    14.             _freeLookActive = Input.GetMouseButton(0);
    15.                      
    16.             if (Input.GetAxis("Mouse ScrollWheel") != 0)
    17.             {
    18.                 MouseWheelZoomCamera();
    19.             }
    20.         }
    21.  
    22.         private float GetInputAxisCustom(string axisName)
    23.         {        
    24.             if (_freeLookActive)
    25.             {
    26.                 switch (axisName)
    27.                 {
    28.                     case "Mouse X":
    29.                         return Input.GetAxis("Mouse X");
    30.  
    31.                     case "Mouse Y":
    32.                         return Input.GetAxis("Mouse Y");
    33.  
    34.                     case "Mouse ScrollWheel":
    35.                         return Input.GetAxis("Mouse ScrollWheel");                    
    36.  
    37.                     default:
    38.                         Debug.Log("Axis returned 0");
    39.                         break;
    40.                 }
    41.             }
    42.  
    43.             if (axisName == "Mouse ScrollWheel")
    44.             {
    45.                 return Input.GetAxis("Mouse ScrollWheel");
    46.             }
    47.  
    48.             return 0;
    49.         }    
    50.  
    51.         public void MouseWheelZoomCamera()
    52.         {
    53.             if (originalOrbits != null)
    54.             {
    55.                 zAxis.Update(Time.deltaTime);
    56.                 float scale = Mathf.Lerp(minScale, maxScale, zAxis.Value);
    57.                 for (int i = 0; i < originalOrbits.Length; i++)
    58.                 {
    59.                     freelook.m_Orbits[i].m_Height = originalOrbits[i].m_Height * scale;
    60.                     freelook.m_Orbits[i].m_Radius = originalOrbits[i].m_Radius * scale;
    61.                 }            
    62.             }
    63.         }
     
    NSokolovskyi and naby-pixiv like this.
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Could you export a small unitypackage that shows this happening, and post it here? It would then be much easier for someone to look at it and help you.
     
  3. Zyrathius

    Zyrathius

    Joined:
    Dec 18, 2012
    Posts:
    20
    Sure will, I'll work on making a small repro and post up. Probably be early next week before I'm back but definitely will follow up.

    Thanks for the advice
     
  4. Zyrathius

    Zyrathius

    Joined:
    Dec 18, 2012
    Posts:
    20
    Ok, here is an export of a very stripped down scene that illustrates the issue I'm having.

    As you zoom in or out, you will notice that when you change directions of the zoom by reversing the mouse wheel, it will initially continue in the same direction for a moment before it finally reverses and matches the mousewheel. It just doesn't "feel" right.

    Am I missing a setting that could "tighten" it up?
     

    Attached Files:

    NSokolovskyi likes this.