- Home /
Handling Cinemachine Freelook Camera with Touch Input to pan
I've implemented Unity's Cinemachine and I can alter it's values through script (like value of axes etc). Now I was able to successfully control the free look camera using touch input to change camera's rotation in the X axis (left right).
However here's my problem. When I swipe to either left or right then stopped but didn't lift my finger, the camera continues to move to that direction after then stops at a certain point (I assume is stops to what my X values we're passed to). But when I swipe then lift my finger immediately, the camera stops rotating immediately as well. (Which is what I want to achieve when I swipe and kept my finger stationary, I also want the camera to stop if stationary)
here's my code below: (PS: TouchPhase.Stationary
didn't worked or I might've used it wrong)
foreach (Touch touch in Input.touches)
{
//override mouse x of camera
if (touch.phase == TouchPhase.Began) //get first touch or current touch
{
initTouch = touch;
}
else if (touch.phase == TouchPhase.Moved)//touch is moving
{
//swiping action
float deltax = initTouch.position.x - touch.position.x;
//check if swiping in camera and not involve jostick touch;
if (RectTransformUtility.RectangleContainsScreenPoint(touchArea, initTouch.position) && RectTransformUtility.RectangleContainsScreenPoint(touchArea, touch.position))
{
if (deltax > 1f)
{
deltax = 1f;
}
else if (deltax < 0f)
{
deltax = -1f;
}
// IM TRYING IT HERE
if (touch.phase == TouchPhase.Stationary)
{
freelookCam.m_XAxis.Value += 0f;
}
else
{
freelookCam.m_XAxis.Value += deltax * touchSensitivity;
}
}
}//THIS CODE WORKS IF I LIFT MY FINGER AND CAMERA STOPS TO MOVE
else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Stationary)
{
freelookCam.m_XAxis.Value += 0f;
}
}
Please ask if I sound confusing. Sorry.