Continuing rotation of circle from new point on screen by touch
Hello,I have circle in my game that i use to rotate while draging my finger on the screen.When i take finger off the screen,and then drag from another place,the circle should continue rotating from previous rotation instead of instantly changing rotation.It kinda works but my problem is that sometimes - I can't tell when that happens exactly,the circle jumps to new rotation instead of continuation.Can someone tell me where i have error in my script?
Here's the exact part of the script :
if (Input.touchCount > 0)
{
Vector3 pos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
Vector2 touchPos = new Vector2(pos.x, pos.y);
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
startAngle = Mathf.Atan2(touchPos.y,touchPos.x) * Mathf.Rad2Deg;
if (startAngle <= 0)
{
startAngle += 360;
}
}
angle = Mathf.Atan2(touchPos.y, touchPos.x) * Mathf.Rad2Deg;
if(angle < 0)
angle += 360;
distanceAngle = startAngle - endAngle;
angle -= distanceAngle;
if (angle < 0)
angle += 360;
else if (angle > 360)
angle -= 360;
if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
endAngle = angle;
}
circle.rotation = Quaternion.Euler(0f, 0f,angle);
Comment