Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 TSI25 · May 25, 2017 at 09:08 PM · vrquaternioneulerangles

Need help with Quaternions - Making a VR Combination Lock

Alright so this is sort of complicated, Essentially the user is holding a combination lock in one hand (and can only manipulate it in one hand due to hardware constraints). The lock has 2 pieces, the dial, and the outer lock. In this case the lock is facing forward in the X axis, just cause that's how the model came in. The desired experience is if the user rotates the lock along the Z or the Y axis, the whole lock should comply (dial and outer lock.) if they rotate it along the X then the outer lock should stay visually locked in place, and the inner lock should rotate with their hand as if they were turning it. The position of the outer lock and dial should also always be the same as the players hand, so all we really care about here is how they are rotating it.

I have this behavior almost working by tracking the parent's rotation delta in the X and applying the inverse to the outer lock while keeping the dial's rotation the same as the parent object's rotation. BUT if the user rotates the lock more than 90 degrees left or right in the X axis, then the rotation goes bonkers and starts rotating the outer lock in ways that are not anticipated.

Here is my code. It seems like the solution should be dead simple, but I always have trouble getting quaternions/euler angles to cooperate.

 public class CombinationLock: MonoBehaviour
 {
     public Transform outerLock;
 
     private Vector3 lastEuler = Vector3.zero;
 
 
     private void Update()
     {
         Vector3 currentEuler = transform.localRotation.eulerAngles;
 
         float delta = currentEuler.x - lastEuler.x;
         outerLock.localRotation = Quaternion.Euler(outerLock.localRotation.eulerAngles.x - delta, 0f, 0f);
 
         lastEuler = transform.localRotation.eulerAngles;
     }
 }

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 TSI25 · May 26, 2017 at 01:19 PM

Got it working. Code works, the problem is that I had children under the parent that had 90 degree rotations to make the model face forward. I guess something about preserving those child rotations was making the euler math a lot more complicated than it needed to be, and as long as i had all the children starting out at the same rotation as the parent object it works just fine.

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

85 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change rotation of an object based on an HTC Vive Controller 1 Answer

Camera viewport transformation from one world to the rotated world. 1 Answer

Doing a Star Fox Style barrel roll? how best to rotate a gameobject over a period of time and have it return it's original rotation? 1 Answer

Rotate with raw gyro data. 0 Answers

(Solved) Aligning player to surface while still maintaining look direction 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