Search Unity

Question How do you change/set camera sensitivity on virtual cinemachine camera ?

Discussion in 'Cinemachine' started by IMIv2, Jun 15, 2022.

  1. IMIv2

    IMIv2

    Joined:
    Jun 25, 2018
    Posts:
    13
    I am using a virtual cinemachine camera as a first person camera with cinemachine input provider script to move the camera with my mouse. Is it possible to change how fast the camera moves at X and Y axis ? I want to make a sensitivity sliders for X and Y axis.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    If it's first person, then the camera is locked to the player. Just make the player move faster. The code for that will be in whatever script you're using to move the player.
     
  3. IMIv2

    IMIv2

    Joined:
    Jun 25, 2018
    Posts:
    13
    The camera is not locked to a player, it does follow my player but i can still move the camera around even with a disabled player object or if i make it follow a random box. Looking around is handled by the CinemachineInputProvider script which cannot be modified since it's internal unity script. I assume it handles input that translates to camera movement in the part of the script below and I'd only need to multiply the returned value to increase/decrease camera look around speed.
    Code (CSharp):
    1.         /// <summary>
    2.         /// Implementation of AxisState.IInputAxisProvider.GetAxisValue().
    3.         /// Axis index ranges from 0...2 for X, Y, and Z.
    4.         /// Reads the action associated with the axis.
    5.         /// </summary>
    6.         /// <param name="axis"></param>
    7.         /// <returns>The current axis value</returns>
    8.         public virtual float GetAxisValue(int axis)
    9.         {
    10.             if (enabled)
    11.             {
    12.                 var action = ResolveForPlayer(axis, axis == 2 ? ZAxis : XYAxis);
    13.                 if (action != null)
    14.                 {
    15.                     switch (axis)
    16.                     {
    17.                         case 0: return action.ReadValue<Vector2>().x;
    18.                         case 1: return action.ReadValue<Vector2>().y;
    19.                         case 2: return action.ReadValue<float>();
    20.                     }
    21.                 }
    22.             }
    23.             return 0;
    24.         }
    Can i somehow override this method or something ? Or should i just ditch this script and make the camera control script myself ? I'm quite new to this so sorry if I'm asking dumb questions.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Are you using the FirstPerson StarterAsset package?

    Normally, you can control the intensity using the input actions panel - you should not have to do it in code. The whole point of the input package is to abstract away the inputs from the code. If you double-click on one of the inputs assigned in the input provider inspector, you will get this panel where you can fiddle with the input properties.

    upload_2022-6-15_17-59-49.png
     
  5. Payce

    Payce

    Joined:
    Jan 15, 2020
    Posts:
    7
    Curious if the processors can be added to existing mappings, for example applying the Scale Vector2 with values set by the player. Is this the best way to do this or is there a better design ?
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    That should work. However, you might need to first copy the DefaultInputActions asset (which is inside the input package and is therefore read-only) before making any mods to it.