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 space_bit · Jul 30, 2014 at 02:07 PM · rotationeulerangleskinect

Rotating, stopping, rotating again.

So I'm working on a mechanic with the Kinect that involves turning a wheel. The way I am doing it currently is getting the angle between the player's two hands. (kp refers to kinect stuff, it just tells if the hand is open or closed).

 void Update () {
         heading = lCursor.transform.position - rCursor.transform.position;
             if (kp.rightIsClosed) {
                         currAngle = Mathf.Atan2 (heading.y, heading.x);
                         transform.rotation = Quaternion.Euler (0f, 0f, (Mathf.Rad2Deg * currAngle) - (oldAngle));
                 }
         
             if (kp.rightIsOpen) {
                 oldAngle = transform.eulerAngles.z;
             }
                 
     }

The problem I am having is that when you turn the wheel, let go, re-position your hands, and try to turn again the wheel snaps to the new hand position. What I want is that when you let go, that becomes the new 'zero', imagine turning a valve. Its not one continous turn but several small turns. I tried at the bottom to get the angle when you when you let go as oldAngle and then when you regrab, subtract that value from the new so you are only rotating the new amount. I'm pretty stuck so any help would be greatly appreciated.

Comment
Add comment · Show 3
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 sirbranedamuj · Jul 30, 2014 at 04:26 PM 0
Share

How does the user turn the wheel? Is it with a single hand like wheel of fortune or with two hands price is right style? I'm not sure I understand what lCursor and rCursor are, so I don't understand what heading represents.

avatar image robertbu · Jul 30, 2014 at 06:26 PM 0
Share

Shouldn't you be adding 'oldAngle' not subtracting it?

avatar image space_bit · Jul 30, 2014 at 06:45 PM 0
Share

@sirbranedamuj its like a pirate ship wheel. so its more like they are turning a bar between the two hands.

@robertbu i don't think so. if you turn something 30 degrees, let go and grab it to turn another 30, if you add the first 30 you'd be at 90, not 60. i think my problem is more with getting the value of oldAngle. if the wheel starts at 0 and i grab it and let go it stays at zero. if i grab it a second time it immediately flips to 180(or -180).

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Jul 30, 2014 at 07:02 PM

Here is a quick script for how I might approach the problem. I'm not sure of frame of reference, but I think your heading vector is backwards. That is Vector3.right is the 0.0 angle for Atan2, so looking towards positive 'z' , you want to subtract the left from the right. But maybe the names don't mean what I think.

 private bool grabbed = false;
 private float startAngle = 0.0;
 private Quaternion startRot;
 
 void Update () {
     if (kp.rightIsClosed) {
         Vector3 heading = rCursor.transform.position - lCursor.transform.position;
         float currAngle = Mathf.Atan2(heading.y, heading.x) * Mathf.Rad2Deg;
         if (!grabbed) {
              startAngle = currAngle;
              startRot = transform.roation;
             grabbed = true;
         }
         else {
             currAngle -= startAngle;
             transform.rotation = Quaternion.AngleAxis(currAngle, Vector3.forward) * startRot;
         }
     }  
     else {
         grabbed = false;
     }      
 }

 
Comment
Add comment · Show 1 · 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 space_bit · Jul 30, 2014 at 07:34 PM 0
Share

@robertbu AH! That helped a ton! You are gem, thanks so much. You're solution is spot on if you want to post it as an answer.

avatar image
0

Answer by sirbranedamuj · Jul 30, 2014 at 07:09 PM

 transform.rotation = Quaternion.Euler (0f, 0f, (Mathf.Rad2Deg * currAngle) - (oldAngle));

Setting the rotation like this is not adding to the rotation. You're creating a brand new rotation that is rotating x, y, and z degrees from origin.

If your object was at 30 degrees and they let go, then try to turn another 30 degrees, your object will get set to 0 degrees rotated from origin. You need to add your previous angle to your rotation.

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Character Controller change target direction in degree 1 Answer

Problems caused by non-unique Euler angle solutions 1 Answer

Instantiating an object in front of the player 3 Answers

Camera Zoom from rotation. 0 Answers

how do i set the eular angles of a parent object to the same thing as the child object, without changing the rotation of the child object. 0 Answers


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