Search Unity

How to enable orbit with key?

Discussion in 'Cinemachine' started by Tapiiri, Apr 24, 2019.

  1. Tapiiri

    Tapiiri

    Joined:
    Mar 22, 2019
    Posts:
    13
    I'm using the Freelook camera and while the orbit works nicely I would like to keep the camera static behind the character while enabling the orbit with a key. Is this possible?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    Can you give a more detailed description of the behaviour you want?
    You can always disable orbit input by setting the axis input name to blank.
     
  3. Tapiiri

    Tapiiri

    Joined:
    Mar 22, 2019
    Posts:
    13
    Sure, so I'd like a similar camera that's seen in a lot of RPGs where the camera is at default behind the character and then you can look around by pressing e.g. mouse scroll and moving the mouse around.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    and then what happens when you let go of the button?
     
  5. Tapiiri

    Tapiiri

    Joined:
    Mar 22, 2019
    Posts:
    13
    The camera either returns to the default position or stays where it was when the button was released. Either would be fine.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    By leaving the FreeLook's axis input names blank, you can drive the axis.value yourself, using a script. X axis range is -180...180, and Y axis range is 0...1.

    If you want to allow the FreeLook to drive the axes only while the button is pressed, have a script on the FreeLook set the axis name to blank unless the button is pressed.

    Alternatively, you can intercept CM's call to the input system by installing a callback: CinemachineCore.GetInputAxis(). Your callback can return 0 if the button isn't pressed, otherwise call UnityEngine.Input.GetAxis() to get the actual value. However, this will apply to all CM axis input, not just the FreeLook in question.

    You can enable axis recentering if you want, which will bring the axes back to centered position if no input for a specified period.
     
  7. Tapiiri

    Tapiiri

    Joined:
    Mar 22, 2019
    Posts:
    13
    Many thanks, I'll try those out!