Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 danielrothmann · Apr 23, 2020 at 06:47 AM · rotationvrvector3mathquaternions

VR: Controller rotation delta along other axis

Hi all,

I have been struggling with this one for a little while now and hope one of you guys can help me out.

The goal: Smoothly rotate a dial using a VR controller. Intuitively, I would have thought that could be achieved by having the dial's local rotation (in my case on its forward axis) be offset the difference in the controller's local forward rotation.

This doesn't work because the controller can actually be oriented in many different ways, and still be made to rotate along the dial's forward axis.

How do I calculate how much the controller has rotated in relation to the dial's forward axis? It's similar to SteamVR's Circular Drive, only I need to do it in Unity XR Interaction Toolkit.

Here's a drawing to help illustrate it:

illustration

My code is something like this:

 private void CalculateRotation()
 {
     Quaternion projection = Quaternion.FromToRotation(controller.transform.forward, -dial.transform.forward);
     Quaternion controllerOffset = Quaternion.Inverse(previousControllerRotation) * (controller.transform.rotation * projection);
     previousControllerRotation = controller.transform.rotation;
 
     var newTargetAngle = dial.transform.localRotation.z + controllerOffset.eulerAngles.z;
     newTargetAngle = Mathf.Clamp(newTargetAngle, RotationMin, RotationMax);
     targetAngle = newTargetAngle;
 }


This is not working properly, although I think it is in the right direction (projecting the rotation delta onto the dial's forward axis).

What do you think? Thanks in advance!

94326042-252009739273818-7875937532200878080-n.jpg (98.8 kB)
Comment
Add comment · Show 1
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 danielrothmann · Apr 24, 2020 at 11:28 AM 0
Share

I see a lot of people are following the question, probably because it is hard to find a solution online.

I'm still trying to work it out. The question can be re-formulated like:

If I rotate my controller along any given axis, how many degrees did it move along my dial's forward axis?

Will post the answer here if I figure it out before a kind stranger...

2 Replies

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

Answer by danielrothmann · Apr 26, 2020 at 03:42 PM

I ended up with a simpler solution: Calculate the rotational delta for the controller in Euler angles for the axis you're interested in and add that onto the target angle of the dial.

The code:

 private void ComputeTwistAngle()
 {
     // Calculate simple euler angle offset on desired local axis
     var currentInteractorAngleOnAxis = followingInteractor.transform.localEulerAngles[axisOfRotation];
     var interactorAngleDelta = previousInteractorAngleOnAxis - currentInteractorAngleOnAxis;

     // Helper function from Unity Forums to wrap angle in a range
     interactorAngleDelta = Wrap(interactorAngleDelta, maxRotationalDelta, -maxRotationalDelta);

     // Clamp the angle within dial's rotation limits
     targetAngle = Mathf.Clamp(targetAngle + interactorAngleDelta, MinAngle, MaxAngle);
     previousInteractorAngleOnAxis = currentInteractorAngleOnAxis;
 }


This works because the controller is mostly always facing the dial in such a way, that just getting the euler angle delta on the Z axis feels alright in-game.

It does feel a little hacky though (particularly with the angle wrapping), and does not cover edge cases where the controller is oriented differently, for example on its side.

For now, I am OK with this solution. If someone knows how to improve it, I would love to hear it!

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

Answer by Murray_Zutari · Jul 02, 2021 at 09:34 AM

@danielrothmann Hi, I know this post is old but there is a really great DialInteractable script in the VR sample project on Unity Learn, you can get it straight from the Unity Hub

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

225 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 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 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

How can I turn my cube object to the direction it is traveling? 1 Answer

Rotate a Vector3 direction 3 Answers

How to rotate an object to align with the scenery 1 Answer

How do I Rotate Towards a Plane? 0 Answers

Rotate object instead of camera around it? 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