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

Cinemachine freelook mouse down

Discussion in 'Cinemachine' started by piginhat, Feb 25, 2020.

  1. piginhat

    piginhat

    Joined:
    Feb 17, 2016
    Posts:
    96
    I'm having a heck of a job trying to get the cmfreelook to only update the camera view when the left mouse button is down rather than the default whereby regardless the camera moves whenever the mouse if moved.

    Is there a way to say to cinemachine only allow camera movement if user is moving mouse whilst holding the button down?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,268
  3. piginhat

    piginhat

    Joined:
    Feb 17, 2016
    Posts:
    96
  4. ishmhora

    ishmhora

    Joined:
    Apr 11, 2019
    Posts:
    2
    so I am having a heck of a time trying to figure out exactly how to adapt the linked script to the new input system with the free look. I would like to have an on right mouse button down for the keyboard map but use the right joystick without a button press. I have messed around with modifiers but haven’t had any luck. Any suggestions?
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,268
  6. ishmhora

    ishmhora

    Joined:
    Apr 11, 2019
    Posts:
    2
    So this is what I did put in place but I still can't seem to make the look rotation dependent on a condition. I would like to allow the player to toggle on or off the look rotation. I haven't found anything other than scripts for composites that are well beyond my skills. Any suggestions where to start?
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,268
    You can make a custom version of CinemachineInputProvider that conditionally returns 0 for rotations if they are locked. Copy CinemachineInputProvider.cs, rename it to something else, then modify its GetAxisValue() method to check your locked setting and return 0 if rotation for that axis is locked. Use that new custom version as your input provider.
     
  8. Kaegun

    Kaegun

    Joined:
    May 4, 2018
    Posts:
    15
    I know this is a little late, but here's my first-pass solution to the above problem. I suspect that it fails with controllers where you don't want a button press to allow camera control, but I have not tested that fully yet.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3. using Cinemachine;
    4.  
    5. /// <summary>
    6. /// Extended Unity provided Cinemachine Input Provider, to add ability to have mouse down for look.
    7. /// </summary>
    8. public class CinemachineInputProviderEx : CinemachineInputProvider
    9. {
    10.     /// <summary>Button action for looking</summary>
    11.     [Tooltip("Button action for Look Button")]
    12.     [SerializeField]
    13.     private InputActionReference LookButton;
    14.  
    15.     /// <summary>
    16.     /// Implementation of AxisState.IInputAxisProvider.GetAxisValue().
    17.     /// Axis index ranges from 0...2 for X, Y, and Z.
    18.     /// Reads the action associated with the axis.
    19.     /// </summary>
    20.     /// <param name="axis"></param>
    21.     /// <returns>The current axis value</returns>
    22.     public override float GetAxisValue(int axis)
    23.     {
    24.         if (enabled)
    25.         {
    26.             //    If Action is set, then check that button is pressed, else ignore it.
    27.             if (LookButton != null && LookButton.action != null)
    28.             {
    29.                 if (LookButton.action.ReadValue<float>() == 0.0f)
    30.                     return 0f;
    31.             }
    32.  
    33.             return base.GetAxisValue(axis);
    34.         }
    35.  
    36.         return 0;
    37.     }
    38. }
     
    dcarrickDevTeam likes this.