I’m rotating the main camera around an object. for now only on the X axis. But I see some wierd values for the camera’s rotaion. As I rotate it, I see the camera’s rotation (Camera.main.transform.rotation.eulerAngles) goes up to 90 and then it goes back to 0, after 0 it suddenly jumps to 360 and continues to confuse me. also axis z and axis y change to 180 at some point
this is the code for the camera movement:
private void CameraMovement()
{
foreach (var touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
_previousPosition = _cam.ScreenToViewportPoint(touch.position);
}
else if (touch.phase == TouchPhase.Moved)
{
OnMouseMove(touch.position);
}
}
if (Input.GetMouseButtonDown(0))
{
_previousPosition = _cam.ScreenToViewportPoint(Input.mousePosition);
}
else if (Input.GetMouseButton(0))
{
OnMouseMove(Input.mousePosition);
}
}
private void OnMouseMove(Vector3 moveTo)
{
Vector3 newPosition = _cam.ScreenToViewportPoint(moveTo);
Vector3 direction = _previousPosition - newPosition;
_cam.transform.position = new Vector3(0, 0, 0);
_cam.transform.Rotate(new Vector3(1, 0, 0), direction.y * 180);
_cam.transform.Translate(new Vector3(0, 0, -distanceToTarget));
_previousPosition = newPosition;
}
Can anyone please explain to me why and how does it happen?
thanks!