• 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
Question by w88dy · Aug 31, 2017 at 11:18 PM · rotationvrquaternionrotate objecteulerangles

Change rotation of an object based on an HTC Vive Controller

I'm having difficulty trying to alter the position of an object which I'm moving based on an HTC Vive controller. I want the object to follow the controller, which I've achieved by making the object's position the same as the controller:

 gameObject.transform.localPosition = new Vector3(viveController.transform.localPosition.x, viveController.transform.localPosition.y, viveController.transform.localPosition.z);

For the rotation I don't want to completely copy the controller. I want the object (imagine a long rectangle) to be pointing upwards at 45 degrees at all time, which I believe is the X axis, while mirroring the Y and Z axis. I'm doing this by:

 gameObject.transform.eulerAngles = new Vector3(45.0f, viveController.transform.localRotation.eulerAngles.y, viveController.transform.localRotation.eulerAngles.z); 

Which works as I expect if I'm holding the controller flat or pointing slightly upwards to the ceiling, but as soon as I point the controller down towards the floor the object's 45 degree angle pointing upwards flips (mirrors) to 45 degrees pointing down.

I believe this is because the three axes don't appear to be individually changed, i.e. a change to the X axis in the 3D space will also change the Y and Z axes as well. What is happening and how can I achieve what I want? The object should always be pointing upwards regardless of the controllers orientation. Any advice on how to change a single axis without changing the other two would be appreciated!

I've tried a few things including trying localEulerAngles and some Quaternion stuff but I don't really know what to search online to solve my issue. I'm trying to get the object to point at a global 45 degrees, and not relative to the controller. Thanks!

Comment

People who like this

0 Show 0
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

Answer by XpctD · Mar 31, 2021 at 05:31 PM

Hi there @w88dy . Is it possible to add a rotation constraint component? Here is an example I used:

alt text


rotationconst.png (26.9 kB)
Comment

People who like this

0 Show 3 · 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 HellsHand · Mar 31, 2021 at 05:39 PM 0
Share

I'm glad I'm not the only one that responds to 4 year old threads =)

avatar image XpctD · Mar 31, 2021 at 05:40 PM 0
Share

Ahahaha oops, I just saw it in related questions and didn't bother to check.

avatar image HellsHand XpctD · Mar 31, 2021 at 05:42 PM 0
Share

I believe that would work though, haven't played with Vive in Unity in awhile though.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

117 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

Related Questions

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

Why is this rotation not performed as expected? 1 Answer

When applying a 90 degree rotation to Euler Angles, it is over/undershooting sometimes.. 2 Answers

Rotate object based on rotation of SteamVR Controller? 2 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