I’m using Legacy Input, touch.deltaPositionto control virtual camera rotation.
In one script, camera only rotates when drag, but in another script, camera rotates right after I touch the screen and just begin the drag.
My code is very simple, the script 1 gives desired result, that the camera rotates only when I drag. During the test, all touches are 1 finger touch and drag.
I hope to know why in Script 2 with the virtual camera 3rd person follow mode, the camera rotates as soon as I touched the screen before I begin to drag.
Script 1, desired - CinemachineFreeLook
private CinemachineFreeLook currentVCam;
private float dragSpeed = 1f;
public void Update()
{
if (Input.touchCount > 0)
{
foreach (var touch in Input.touches)
{
currentVCam.m_XAxis.m_InputAxisValue = touch.deltaPosition.x * dragSpeed * Time.deltaTime;
currentVCam.m_YAxis.m_InputAxisValue = touch.deltaPosition.y * dragSpeed * Time.deltaTime;
break;
}
}
}
Script 2, not desired - Virtual Camera, 3rd Person Follow
public Cinemachine.AxisState yAxis;
public Cinemachine.AxisState xAxis;
private float dragSpeed = 1f;
public Transform LookAtTarget;
void Update()
{
if (Input.touchCount > 0)
{
foreach (var touch in Input.touches)
{
xAxis.m_InputAxisValue = touch.deltaPosition.x * dragSpeed * Time.deltaTime;
yAxis.m_InputAxisValue = touch.deltaPosition.y * dragSpeed * Time.deltaTime;
break;
}
}
xAxis.Update(Time.deltaTime);
yAxis.Update(Time.deltaTime);
LookAtTarget.eulerAngles = new Vector3(yAxis.Value, xAxis.Value, 0f);
}
Thanks very much.