I am trying to make Basic Touch behaviors for my game where i want to
- Pan Camera by Single finger touch.
- Zoom Camera by pinch With two fingers ofCourse.
- Rotate Camera by two fingers rotation.
- Rotate camera around an object and move only in x axis using Two fingers y position.
i am having problem in making camera to rotate on X axis but i am not able to do it correctly plz help and it also conflicts with my pan behaviour when input is given
public float comfortZoneVerticalSwipe_A = 10;
public float comfortZoneHorizontalSwipe = 50;
public float minSwipeDistance = 100;
public float startTime;
public Vector2 startPos;
public float maxSwipeTime = 0.5f;
if (Input.touchCount > 0 && Input.touchCount < 2)
{
Touch touch = Input.touches[0];
switch (touch.phase)
{ //following are 2 cases
case TouchPhase.Began: //here begins the 1st case
startPos = touch.position;
startTime = Time.time;
break; //here ends the 1st case
case TouchPhase.Moved:
Vector3 offset = transform.right * (-Input.touches[0].deltaPosition.x * 0.9f) * panSpeed + transform.up * (-Input.touches[0].deltaPosition.y * 0.9f) * panSpeed;
Vector3 newTargetOffset = Vector3.ClampMagnitude(offset, maxOffsetDistance);
transform.position += newTargetOffset - targetOffset;
break;
case TouchPhase.Ended: //here begins the 2nd case
float swipeTime = Time.time - startTime;
float swipeDist = (touch.position - startPos).magnitude;
Debug.Log("Mathf.Abs(touch.position.x - startPos.x) " + Mathf.Abs(touch.position.x - startPos.x));
Debug.Log("swipe Time " + swipeTime);
Debug.Log("swipe Dist " + swipeDist);
if (Mathf.Abs(touch.position.x - startPos.x) < comfortZoneVerticalSwipe_A && swipeTime < maxSwipeTime && swipeDist > minSwipeDistance && Mathf.Sign(touch.position.y - startPos.y) > 0)
{
Debug.LogWarning(transform.rotation.x);
transform.rotation = new Quaternion(transform.rotation.x - 5 , transform.rotation.y , transform.rotation.z , transform.rotation.w);
if (transform.rotation.x > 0.2)
{
transform.Rotate(Vector3.right, -2);
}
Debug.LogError(transform.rotation.x);
Debug.LogWarning("Up");
}
else if (Mathf.Abs(touch.position.x - startPos.x) > comfortZoneVerticalSwipe_A && swipeTime > maxSwipeTime && swipeDist > minSwipeDistance && Mathf.Sign(touch.position.y - startPos.y) < 0)
{
transform.rotation = new Quaternion(transform.rotation.x - 5 , transform.rotation.y , transform.rotation.z , transform.rotation.w);
if (transform.rotation.x < 0.9)
{
transform.Rotate(Vector3.right, 2);
}
print("down");
}
break; //here ends the 2nd case
}
}