Touch Camera Rotation

Hi guys!
Im really done of scripting this script
This script i ve done almost perfect but when im moving camera and second finger touched any zone, camera rotating to another zone
Help me to fix that please or give any another code
I just need to control camera and move player at one time but i cant do it properly
here s the code:
Thanks

void IsOnCameraPanel()
{
if(Input.GetTouch(0).phase == TouchPhase.Began )
{
firstpoint = Input.GetTouch(0).position;
xAngTemp = xAngle;
yAngTemp = yAngle;
firstTouch=true;
}

if(Input.GetTouch(0).phase==TouchPhase.Moved)
{
secondpoint = Input.GetTouch(0).position;
//Mainly, about rotate camera. For example, for Screen.width rotate on 180 degree
xAngle = xAngTemp + (secondpoint.x - firstpoint.x) * 20 * XSensitivity / Screen.width;
yAngle = yAngTemp - (secondpoint.y - firstpoint.y) * 15 * YSensitivity / Screen.height;
//Rotate camera
this.transform.rotation = Quaternion.Euler(yAngle, xAngle, 0.0f);
}

if(Input.GetTouch(1).phase == TouchPhase.Began)
{
firstpoint = Input.GetTouch(1).position;
xAngTemp = xAngle;
yAngTemp = yAngle;
secondTouch=true;
}
if(Input.GetTouch(1).phase==TouchPhase.Moved)
{
secondpoint = Input.GetTouch(1).position;
//Mainly, about rotate camera. For example, for Screen.width rotate on 180 degree
xAngle = xAngTemp + (secondpoint.x - firstpoint.x) * 20 * XSensitivity / Screen.width;
yAngle = yAngTemp - (secondpoint.y - firstpoint.y) * 15 * YSensitivity / Screen.height;
//Rotate camera
this.transform.rotation = Quaternion.Euler(yAngle, xAngle, 0.0f);
}
}

Try this…

if (Input.touchCount > 0)
            {
                //Touch began, save position
                if (Input.GetTouch(0).phase == TouchPhase.Began)
                {
                    firstpoint = Input.GetTouch(0).position;
                    xAngTemp = xAngle;
                    yAngTemp = yAngle;
                }
                //Move finger by screen
                if (Input.GetTouch(0).phase == TouchPhase.Moved)
                {
                    secondpoint = Input.GetTouch(0).position;
                    //Mainly, about rotate camera. For example, for Screen.width rotate on 180 degree
                    yAngle = yAngTemp - (secondpoint.y - firstpoint.y) * 90.0f / Screen.height;
                    float swipeSpeed = Input.touches[0].deltaPosition.magnitude / Input.touches[0].deltaTime;
                    yAngle -= Input.touches[0].deltaPosition.y * ySpeed * Time.deltaTime * swipeSpeed * 0.00001f;
                    //Clamp the vertical axis for the orbit
                    yAngle = ClampAngle(yAngle, yMinLimit, yMaxLimit);
                    if (yAngle > 90 && yAngle < 270)
                        xAngle = xAngTemp - (secondpoint.x - firstpoint.x) * 180.0f / Screen.width;
                    else
                        xAngle = xAngTemp + (secondpoint.x - firstpoint.x) * 180.0f / Screen.width;
                    if (xAngle <= 0)
                        xAngle += 360;
                    if (xAngle > 360)
                        xAngle -= 360;
                    transform.rotation = Quaternion.Euler(yAngle, xAngle, 0.0f);
                }
            }
2 Likes