Search Unity

New Input System and Cinemachine.

Discussion in 'Cinemachine' started by dytrychrafal, Aug 29, 2021.

  1. dytrychrafal

    dytrychrafal

    Joined:
    Sep 6, 2020
    Posts:
    32
    Hello,
    How can i rotate cinemachine camera on mouse button down? I added Cinemachine Input Provider to the Cinemachine Camera.



    In old input system i used this script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Cinemachine;
    5. public class CMFreelookOnlyWhenRightMouseDown : MonoBehaviour {
    6.     void Start(){
    7.         CinemachineCore.GetInputAxis = GetAxisCustom;
    8.     }
    9.     public float GetAxisCustom(string axisName){
    10.         if(axisName == "Mouse X"){
    11.             if (Input.GetMouseButton(1)){
    12.                 return UnityEngine.Input.GetAxis("Mouse X");
    13.             } else{
    14.                 return 0;
    15.             }
    16.         }
    17.         else if (axisName == "Mouse Y"){
    18.             if (Input.GetMouseButton(1)){
    19.                 return UnityEngine.Input.GetAxis("Mouse Y");
    20.             } else{
    21.                 return 0;
    22.             }
    23.         }
    24.  
    25.         return UnityEngine.Input.GetAxis(axisName);
    26.     }
    27. }
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
  3. dytrychrafal

    dytrychrafal

    Joined:
    Sep 6, 2020
    Posts:
    32
    Hi Again,
    @gaborkb thanks for your answer,
    I'm to newbie to solve my problem by myself;/ Tried to do it following this documentation:
    https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Actions.html#creating-actions
    but don't understand how to put it all together.
    How can i get mouse button down here:

    myAction.AddCompositeBinding("ButtonWithOneModifier")
    .With("Button", "<Keyboard>/1")
    .With("Modifier", "<Keyboard>/leftCtrl")
    .With("Modifier", "<Keyboard>/rightCtrl");


    Do i need to write custom script and write new action or can i use somehow my PlayerActions LookControls?

    //Edit
    I found old Brackeys video about InputSystem from 2018 and there was Mouse > leftButton / rightButton in Binding. Why it's no longer there?
     
    Last edited: Aug 29, 2021
  4. BRGames_

    BRGames_

    Joined:
    Jun 24, 2021
    Posts:
    20
    It's actually pretty easy:
    1)
    Check this tutorial to understand how to link Cinemachine with the new input system using an input provider (at 1':24")


    2) From the "Input Actions" file that you have just created:
    - Right click on the Action "MouseLook" (I'm supposing that you have watched tutorial at point 1) and used the same naming of the tutorial)
    - Select "Add Binding With One Modifier"
    - In the new line that will appear
    - Select "Modifier" and set "Left Button [Mouse]" for the "Path" property under "Binding"
    - Select "Binding" and set "Delta [Mouse]" for the "Path" property under "Binding"

    You should arrive at something similar to this:
    mouselook.PNG