# Camera rotate through touch drag

Camera rotate through touch drag.

I want to rotate the camera using a touch drag.

So I saw many scripts through Google search.

Touch often looks at strange camera.

Let me know what the problem is.

It’s what I’m testing.

``````if (Input.touchCount > 0)
{
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
FirstPoint = Input.GetTouch(0).position;
xAngleTemp = xAngle;
yAngleTemp = yAngle;
}
if (Input.GetTouch(0).phase == TouchPhase.Moved)
{
SecondPoint = Input.GetTouch(0).position;
xAngle = xAngleTemp + (SecondPoint.x - FirstPoint.x) * 180 / Screen.width;
yAngle = yAngleTemp - (SecondPoint.y - FirstPoint.y) * 90 * 3f / Screen.height;

if (yAngle < -80f)
yAngle = -80f;
if (yAngle > 80f)
yAngle = 80f;
transform.rotation = Quaternion.Euler(yAngle, xAngle, 0.0f);
}
}
``````

I just checked and there’s no problem if you build and test Android. But I build and test with WebGL and the screen turns on in WebGl.

Is there a solution in WebGl?

What does ‘the screen turns on’ mean exactly?

When you build and test a platform using WebGL, sometimes the camera looks the other way or at a strange place when you touch drag.

Hm if it works on mobile then the code should be ok.

I’d just start using Debug.Log and the Javascript Console to see what is going on, and if that’s hard to read then maybe visualize the drag with a line to see if anything is getting messed up.

I can’t say for sure if you would run into gimbal lock with that code, but just in case, perhaps use two ‘rotator’ Transforms (with the vertical rotator a child of the horizontal rotator) so that you can apply the rotations to each transform locally around one axis.

Thank you.
I’m doing a test and I’m doing touch tap.
Then (SecondPoint.x - FirstPoint.x), (SecondPoint.y - FirstPoint.y) This is normal only when the value is normally zero.

However, if you touch tap in WebGL, the value fluctuates from 600 to -600 every time.

I don’t’ know the reason.

When you say ‘tap’ you mean you only press it for an instant? And the problem is only with the tap, not drag?

Should be pretty easy to check if it’s a tap by the time since the touch was started, and then ignore it.

I have no idea why the values would behave like that, though I’m not sure I understand your explanation perfectly well.

I think I’ve confused you.

I mean the difference between the first and second points coming in early.

The strange value of Touch seems to be causing trouble.

Sorry, I don’t follow. What do you mean by ‘coming in early’?

Perhaps if you could take a video it would explain things in a clearer way

I don’t think it’s going to be easy.

I think the Touch Position value in WebGL comes in strangely once.

So the value of SecondPoint.x, SecondPoint.x, and FirstPoint.y, it seems to be changing greatly, making the camera look like it’s looking at a strange place.