Circular Rotation Input

Hello,

I have this top down view of a table that I want to be able to rotate around on its Y axis via a finger swipe (mouse swipe), but I want it to be a circular gesture. What I mean by that is currently, if you swipe anywhere on the screen, the table will rotate anticlockwise. I want it so your finger can actually rotate the table itself, around its y axis.

Example:

  • I swipe my finger from left to right on the lower portion of the screen, the table will rotate anticlockwise, as if its following my finger.
  • I swipe my finger from left to right on the upper portion of the screen, the table will roate clockwise, as if its following my finger.
  • I swipe my finger from bottom to top, on the left portion of the screen, the table will rotate clockwise, etc.

So basically, if I move my finger in a circular motion around the table, the table itself will continually rotate with my finger.

How will I introduce a system like this?

Thanks

When you first put the finger down, you calculate the angle between the middle point of the screen and your finger. You can use Mathf.Atan2 for that.

Then while you move your finger, you calculate the angle every frame and the difference between the starting angle and your current is what you add to the starting angle(also needs to be saved on start) of the table.

Now you only have to handle multiple turns right, so you don’t jump from 360 to 0 again. You can do this by manipulating the starting angle on every turn in the opposite direction. This can be tricky as the jump occures at the mathematical 0 angle point, which is not your starting angle, but you’ll see when you get there.