0

Recently I have been trying to get my camera to rotate the same way it does in Pokemon Go and by that I mean whenever the player does a circular touch gesture(like the below picture) the camera rotates that way too and if they reach back to the original point where they started, the rotation keeps going. Also the ability to rotate like this both to the right and the left is something I have yet to replicate. enter image description here

I have tried various code pieces but to no avail. I am trying to get my camera to rotate only on the Z axis, as I need my X rotation as 90* and Y as 0.

If anybody has a clue on how to do this I would appreciate it :)

if(Input.touchCount==1 && inputsPaused == false)
        {
 
 
            Touch firstTouch = Input.GetTouch(0);
 
 
 
            //if (firstTouch.deltaPosition.y > 0)
            //{
            //    if (firstTouch.deltaPosition.x < 0)
            //    {
            //        transform.eulerAngles += new Vector3(0, 0, -40f * Time.deltaTime);
            //        compas.Rotate(new Vector3(0, 0, -4f * Time.deltaTime));
            //    }
            //    else
            //         if (firstTouch.deltaPosition.x > 0)
            //    {
            //        transform.eulerAngles += new Vector3(0, 0, 40f * Time.deltaTime);
            //        compas.Rotate(new Vector3(0, 0, -4f * Time.deltaTime));
            //    }
 
            //}
            //else
            //    if (firstTouch.deltaPosition.y < 0)
            //{
            //    if (firstTouch.deltaPosition.x < 0)
            //    {
            //        transform.eulerAngles += new Vector3(0, 0, 40f * Time.deltaTime);
            //        compas.Rotate(new Vector3(0, 0, -4f * Time.deltaTime));
            //    }
            //    else
            //         if (firstTouch.deltaPosition.x > 0)
            //    {
            //        transform.eulerAngles += new Vector3(0, 0, -40f * Time.deltaTime);
            //        compas.Rotate(new Vector3(0, 0, -4f * Time.deltaTime));
            //    }
            //}
 
            if (firstTouch.position.y > 0)
            {
               
                    transform.eulerAngles += new Vector3(0, 0, -40f * Time.deltaTime);
                    compas.Rotate(new Vector3(0, 0, -4f * Time.deltaTime));
             
 
            }
            else
                   if (firstTouch.position.y < 0)
            {
               
               
                    transform.eulerAngles += new Vector3(0, 0, 40f * Time.deltaTime);
                    compas.Rotate(new Vector3(0, 0, -4f * Time.deltaTime));
               
             
            }
 
 
 
            text.text = "X: " + firstTouch.position.x + " Y: " + firstTouch.position.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;
            //}
 
            //transform.rotation = Quaternion.Euler(transform.rotation.x, transform.rotation.y, angle);
 
        }
 
     
 
 
 
 
 
 
 
    }
  • Recognizing a circular gesture is beyond trivial .. even more when you need to already recognize the circle while dragging => you will need to a) store some of the previous frames touch positions b) estimate a common center point for those -> you need at least 3 positions before being able to determine a circle which they all three fall on c) allow some variance since you user won't draw a perfect circle d) calculate, track and apply the already covered angle – derHugo Feb 24 '23 at 16:31
  • I don't really understand why you would rotate one thing using `40 * Time.deltaTime` while you rotate the other thing using `4 * Time.deltaTime` of course that will go off sync – derHugo Feb 24 '23 at 16:33
  • Apologies for the 40* and 4* I was not using that script anymore, I had it there just to showcase other methods I have tried. I will try to implement a script that follows your method. Thank you! – Bogdan Radoi Feb 24 '23 at 17:28

0 Answers0