Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by oliver-jones · Jan 24, 2014 at 11:17 AM · rotationpositionclockgesture

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by HappyMoo · Jan 24, 2014 at 11:26 AM

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.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image oliver-jones · Jan 24, 2014 at 11:46 AM 0
Share

Okay, so I've got this so far:

 var initialFingerLocation : Vector2;
 var currentFingerLocation : Vector2;
 var currentAngle : float;
 
 function Update () {
 
     var middlePoint = Vector2(Screen.width/2, Screen.height/2);
 
     if(Input.GetButtonDown("Fire1")){
 
         initialFingerLocation = Vector2(Input.mousePosition.x - middlePoint.x, Input.mousePosition.y - middlePoint.y);
     }
 
     if(Input.GetButton("Fire1")){
 
         if(initialFingerLocation != Vector2(0,0))
             currentFingerLocation = Vector2(Input.mousePosition.x - middlePoint.x, Input.mousePosition.y - middlePoint.y);
     }
 
     if(Input.GetButtonUp("Fire1")){
 
         initialFingerLocation = Vector2(0,0);
         currentFingerLocation = Vector2(0,0);
     }
 
 
     var vec2 = currentFingerLocation - middlePoint;
     currentAngle = $$anonymous$$athf.Atan2(vec2.y, vec2.x);
 
 }

$$anonymous$$y current angle is only giving out readings between: -2.5 and -1.5, which doesn't sound right to me?

avatar image HappyMoo · Jan 24, 2014 at 11:49 AM 0
Share

Atan2 gives you rad angles... multiply by $$anonymous$$athf.Rad2Deg if you want degrees

avatar image oliver-jones · Jan 24, 2014 at 12:34 PM 0
Share

Okay - the value I'm getting is better, ranges from -180 to +180. I guess this is the bit you were referring to when the value 'jumps'?

avatar image HappyMoo · Jan 24, 2014 at 01:10 PM 0
Share

yes, you need to save your last angle in a var and when you jump signs, but not close to 0, but close to 180, you need to count turns.

 float turns = 0;
 ...
 if (($$anonymous$$ath.Sign(currentAngle) != $$anonymous$$athf.Sign(lastCurrentAngle)) && $$anonymous$$ath.Abs(currentAngle)>90) {
     // this may be the wrong direction. if so, use -360 ins$$anonymous$$d of 360
     turns += 360 * $$anonymous$$ath.Sign(currentAngle);
 }
 ...
 tablerotation = turns + currentAngle - startAngle
avatar image oliver-jones · Jan 24, 2014 at 02:38 PM 0
Share

Awesome, got it working now. Thanks! $$anonymous$$uch appreciated.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unfreezing rotation causes the position and rotation go crazy 0 Answers

!CompareApproximately (det, 1.0F, .005f) 2 Answers

Problem with rotation of objects 0 Answers

transform.position on basis of rotation 0 Answers

Firing towards mouse- aim in all directions? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges