How to move Cinemachine FreeLook camera with touch input?
I've recently installed Cinemachine and I am trying to use a FreeLook virtual camera. The FreeLook camera is not responding to my touch input when I run in Unity remote.
When I tried writing a script to control the virtual camera transform.position based on touch input, the virtual camera did not change position but instead stayed locked to the offset set up in the component.
Does anyone have a solution for working with touch input and Cinemachine virtual cameras?
Thank you.
Answer by Jean-Fabre · Mar 27, 2018 at 01:29 PM
Hi,
You need to implement the GetInputAxis delegate:
CinemachineCore.GetInputAxis = HandleAxisInputDelegate;
here is a working Component that works, simply drop it on any GameObject in your scene:
you can also get it on the PlayMaker Ecosystem or github, more info here: https://twitter.com/JeanAtPlayMaker/status/978915559994740736
using Cinemachine;
using UnityEngine;
public class CinemachineCoreGetInputTouchAxis : MonoBehaviour {
public float TouchSensitivity_x = 10f;
public float TouchSensitivity_y = 10f;
// Use this for initialization
void Start () {
CinemachineCore.GetInputAxis = HandleAxisInputDelegate;
}
float HandleAxisInputDelegate(string axisName)
{
switch(axisName)
{
case "Mouse X":
if (Input.touchCount>0)
{
return Input.touches[0].deltaPosition.x / TouchSensitivity_x;
}else{
return Input.GetAxis(axisName);
}
case "Mouse Y":
if (Input.touchCount > 0)
{
return Input.touches[0].deltaPosition.y / TouchSensitivity_y;
}
else
{
return Input.GetAxis(axisName);
}
default:
Debug.LogError("Input <"+axisName+"> not recognyzed.",this);
break;
}
return 0f;
}
}
Bye,
Jean
Dude... This is amazing. Dropped it right in and it worked. Thanks man.
This works perfectly!! Can you please write the code that will not let touch pass through Ui gameobjects?
I already tried IsPointerOverGameobject(Input.GetTouch(0).fingerId) but that always evaluates to false
Your answer
![](https://koobas.hobune.stream/wayback/20220612131427im_/https://answers.unity.com/themes/thub/images/avi.jpg)