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 $$anonymous$$ · Feb 22, 2017 at 09:14 AM · rotationvrpitch

Apply PitchRotation to object based on the rotation of another object

I have an object A, that can have a starting rotation of anything. I have a second object B that points at A that has a variable pitch up/down relative to A. I would like to apply only the pitch of B pointed at A(I dont want roll or yaw).

A physical example would be a laser pointer pointing at a wall, if you pitch the laser pointer down, the wall has the same pitch applied mirroring the laser pointer. But I dont want the roll or yaw to effect the wall.

The real use case here is that I am building a VR interaction system where the final component to the movement/rotation is the ability to pitch the rotation of a held object based on the players hand(two actually). I have everything working from rotation about the player and rotation relative to both hands, but I just cant get the hand pitch to work which would complete the process.

I would love to just apply the world rotation of the controller straight to the object im grabbing but I cant because if you rotate so that you are facing backwards, the whole thing breaks, I can only use the pitch rotation on the target object. This has been fiendishly difficult, probably because I am not a superstar at quaternions yet. Here is my current block of code that I am playing with, this sort of works except when I face a particular angle, the x axis value just doesnt change even when I drop it into local rotation.

 // Getting the rotation based in the change of the controller up vector
 Quaternion leftQuat = Quaternion.FromToRotation(oHintLeft, leftTrans.up);
 //Quaternion rightQuat = Quaternion.FromToRotation(oHintRight, rightTrans.up);


  // Cheat to get the leftQuat rotation into local rotation for the object im 
 // trying  to pitch
 Quaternion objRotation = objectToGrab.rotation;
 objectToGrab.rotation = leftQuat;
 Quaternion localRotation = objectToGrab.localRotation;
 objectToGrab.rotation = objRotation;

 // older attempt to get the local relative rotation
 //leftQuat = Quaternion.Inverse(gameObjectRef.transform.rotation) * leftQuat;


 // attempting to remove all the other axis values except for x(which should be pitch in local
 leftQuat = Quaternion.Euler(localRotation.eulerAngles.x, 0, 0);
 //rightQuat = Quaternion.Euler(rightQuat.eulerAngles.x, 0, 0);

 // Finally applying the pitch rotation to the local rotation
 objectToGrab.localRotation = originalLocalRotation * leftQuat;

Any insight would save me some hair loss thank you!

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

0 Replies

· Add your reply
  • Sort: 

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

Disable Windows Mixed Reality headset rotation/position tracking 1 Answer

How to flip the Steam VR Play Area when loading a new scene? 0 Answers

Android: how do i make the rotation of my player follow the rotation of my phone 1 Answer

Rotating Cube with oculus touch controllers 0 Answers

Setting camera pitch - Never works? 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