Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

POV Camera tied to mobile input

Discussion in 'Cinemachine' started by AntLewis, Feb 13, 2019.

  1. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    254
    Hey, I notice POV camera is driven by MouseX and MouseY axis, as defined in the input manager. This doesn't seem to work out of the box for mobile (via Unity Remote anyway - I actually thought it would have).

    Is there an best practise for making the POV camera respond to mobile input? Thanks!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Look at CinemachineTouchInputMapper
     
    AntLewis likes this.
  3. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    254
    Ok grabbed this script from elsewhere which implements a GetInputAxis delegate. It's picking up input alright (through logging the values), but for some reason the result is a camera that just seems to shake (it seems to want to return to the centre, resulting in very erratic behaviour. Note I dont have centring of either axis enabled.

    Cheers

    Code (CSharp):
    1. using Cinemachine;
    2. using UnityEngine;
    3.  
    4.  
    5. public class CinemachineCoreGetInputTouchAxis : MonoBehaviour
    6. {
    7.  
    8.     public float TouchSensitivity_x = 10f;
    9.     public float TouchSensitivity_y = 10f;
    10.  
    11.     // Use this for initialization
    12.     void Start()
    13.     {
    14.         CinemachineCore.GetInputAxis = HandleAxisInputDelegate;
    15.     }
    16.  
    17.     float HandleAxisInputDelegate(string axisName)
    18.     {
    19.         switch (axisName)
    20.         {
    21.  
    22.             case "Mouse X":
    23.  
    24.                 if (Input.touchCount > 0)
    25.                 {            
    26.                     return Input.touches[0].deltaPosition.x / TouchSensitivity_x;
    27.                 }
    28.                 else
    29.                 {                  
    30.                     return Input.GetAxis(axisName);
    31.                 }
    32.  
    33.             case "Mouse Y":
    34.                 if (Input.touchCount > 0)
    35.                 {          
    36.                     return Input.touches[0].deltaPosition.y / TouchSensitivity_y;
    37.                 }
    38.                 else
    39.                 {
    40.                     return Input.GetAxis(axisName);
    41.                 }
    42.  
    43.             default:
    44.                 Debug.LogError("Input <" + axisName + "> not recognyzed.", this);
    45.                 break;
    46.         }
    47.  
    48.         return 0f;
    49.     }
    50. }
     

    Attached Files:

  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    I don't understand why the camera is misbehaving. Must be some interaction with one of your other scripts.
    I added a FreeLook vcam to an empty scene, attached your script, and it worked perfectly.
     
  5. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    254
    Ok thanks for checking.