Search Unity

Cinemachine FreeLook jumps around on iOS

Discussion in 'Cinemachine' started by MSachs, Jan 18, 2019.

  1. MSachs

    MSachs

    Joined:
    Nov 22, 2017
    Posts:
    122
    Hi,

    I have a Cinemachine FreeLook Cam in a scene which can be rotated around a target. In playmode in Unity everything works as expected.
    On iOS in my mind touching the screen shouldn't do anything until I move my finger and then the camera should be rotated from there. But instead when touching the screen the camera moves straight away and rotates from the new position when I move my finger.

    How can I prevent that?

    Thanks in advance
     
  2. MSachs

    MSachs

    Joined:
    Nov 22, 2017
    Posts:
    122
    I made a short video to visualize what I mean exactly. In the clip I only tap the screen on the right, then on the left, right again, left again.
    Why does it move the camera without me moving my finger?

     
  3. MSachs

    MSachs

    Joined:
    Nov 22, 2017
    Posts:
    122
    I got it myself!

    Found the following code online which I had to put into the scene. Now everything works as intended!


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