Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Resolved Turning off the panning when moving

Discussion in 'Cinemachine' started by dasAndy, Mar 6, 2022.

  1. dasAndy

    dasAndy

    Joined:
    Jun 3, 2019
    Posts:
    4
    Hello there

    I have built a top view camera using cinemachine.

    I want the camera to look at the player from above. If you zoom in with the middle mouse button, the camera comes a bit lower behind the player. If you keep the right mouse button pressed, you can rotate the camera around the player.

    This behavior can be done very well and very fine adjustable by cinemachine. For this I used a free look camera with binding on wolrd space and I wrote my own modifiers for the input axes.

    Code (CSharp):
    1.  
    2.     void Start()
    3.     {
    4.          CinemachineCore.GetInputAxis = GetInputAxis;
    5.     }
    6.  
    7.     private float GetInputAxis(string axisName)
    8.     {
    9.         if (axisName == "Mouse Y")
    10.         {
    11.             if (Input.GetMouseButton(2))
    12.             {
    13.                 return Input.GetAxis("Mouse Y");
    14.             }
    15.             return 0f;
    16.         }
    17.  
    18.         if(axisName == "Mouse X")
    19.         {
    20.             if (Input.GetMouseButton(1))
    21.             {
    22.                 return Input.GetAxis("Mouse X");
    23.             }
    24.             return 0f;
    25.         }
    26.  
    27.         return Input.GetAxis(axisName);
    28.     }
    Everything works the way I want it to. Almost.

    When the player moves, there is always a little panning like rotation of the camera. I made a short video (from second 00:10) so you can see what I mean. I could't find a way to turn off this behavior. Can someone maybe help me with this?

     
  2. dasAndy

    dasAndy

    Joined:
    Jun 3, 2019
    Posts:
    4
    By playing around even more, I figured it out myself.
    The damping values for aim and body control this behavior. If I set the values for movement and rotation to 0, the camera is absolutely fixed above the player. If I set the values not equal to 0 but still all equal to each other, the camera still moves very smoothly but the annoying rotation is gone.

    Thanks fpr reading anyway ;)
     
    antoinecharton and Gregoryl like this.