# Problem with camera rotation by swipe

I use a script to rotate the camera with a swipe. To rotate, I use the Device Simulator plugin. If I rotate in the inspector, and then try to rotate the camera in the game with a swipe, then the camera will turn immediately to where it was rotated before rotating in the inspector. If anyone doesn’t understand, you can check how it works. The script hangs on the player, and the camera is in the player. I need to make it so that if I change the values of the rotation of the camera in the inspector, and then rotate it in the game, then the camera does not rotate to where it was rotated before the changes in the inspector…

`````` using UnityEngine;

public class PlayerRotation : MonoBehaviour
{
public Transform myCamera;
Vector3 firstPoint;
Vector3 secondPoint;
float xAngle;
float yAngle;
float xAngleTemp;
float yAnleTemp;
private float slowMouseX;
public float sensitivity = 1f;

void Start()
{
yAngle = transform.localRotation.eulerAngles.y;
}

void Update()
{
foreach (Touch touch in Input.touches)
{
if (touch.position.x > Screen.width / 2.5 & touch.phase == TouchPhase.Began)
{

firstPoint = touch.position * sensitivity;
xAngleTemp = xAngle;
yAnleTemp = yAngle;
}
if (touch.position.x > Screen.width / 2.5 & touch.phase == TouchPhase.Moved)
{
secondPoint = touch.position * sensitivity;
xAngle = xAngleTemp - (secondPoint.y - firstPoint.y) * 90 / Screen.height;
yAngle = yAnleTemp + (secondPoint.x - firstPoint.x) * 180 / Screen.width;
transform.rotation = Quaternion.Euler(0, yAngle, 0);
xAngle = Mathf.Clamp(xAngle, -80, 80);
myCamera.transform.rotation = Quaternion.Euler(xAngle, yAngle, 0);

}
}
}
}
``````

it seems that the issue is related to how the camera’s rotation values are being stored and updated. When you rotate the camera in the inspector, its rotation values are being updated, but the camera’s initial rotation values are still being used when you rotate it in the game with a swipe.

One possible solution is to store the camera’s initial rotation values when the game starts and use them as a reference point when updating the camera’s rotation values in the script. You can do this by adding a variable to store the camera’s initial rotation values and updating it in the Start method:

``````Quaternion cameraInitialRotation;

void Start()
{
yAngle = transform.localRotation.eulerAngles.y;
cameraInitialRotation = myCamera.transform.rotation;
}

myCamera.transform.rotation = cameraInitialRotation * Quaternion.Euler(xAngle, yAngle, 0);
``````