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 · Jun 05, 2017 at 06:20 PM · rotationquaternioneulerangles

Find Opposite Quaternion

I have an object with a rotation being driven by a gyro, and I need the ability to recenter it. I haven't been able to figure out a way to reset the gyro so instead I've been trying to rotate a parent of that object to be the opposite rotation, such that if the child is rotated 90 degrees in the x, the parent will get rotated -90 degrees in the x, thus making it seem as though the child is facing the origin again. I can't quite seem to get this to math out though. Should I be doing something else?

I've tried the following methods but nothing seems to work quite the way i want it to.

 parent.localEulerAngles = new Vector3(
             -child.localEulerAngles.x,
             -child.localEulerAngles.y,
             -child.localEulerAngles.z);
 
 parent.localEulerAngles = new Vector3(
             360f-child.localEulerAngles.x,
             360f-child.localEulerAngles.y,
             360f-child.localEulerAngles.z);
 
 parent.localRotation = Quaternion.Inverse(child.localRotation);
 
 parent.localRotation= Quaternion.LerpUnclamped(child.localRotation, Quaternion.Identity, 2f);


Anyone have any thoughts on what else I should try to get this thing recentered?

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

2 Replies

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

Answer by TSI25 · Jun 05, 2017 at 09:02 PM

Well ultimately i got it working by deleting the child prefab and re instantiating it which is something i was hoping to avoid having to do but will work for now. using Quaternion.Inverse() as JC_SummitTech suggested above seems to work the first time but after that it gets wonky. This probably means that there is a problem deeper in the code elsewhere. I'll update this answer if I can figure out what that is.

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 JC_SummitTech · Jun 05, 2017 at 07:08 PM

Here is what I use

 Quaternion qBase = Quaternion.identity;
 
     //to recenter call
     qBase =  Quaternion.Inverse(Gyro.quat);
 
 
     //updating my current quaternion
     transform.localRotation = qBase * Gyro.quat;


You'll want to filter the gyro data and all but that's probably what you need to "recenter" :)

Comment
Add comment · Show 4 · 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 TSI25 · Jun 05, 2017 at 07:35 PM 0
Share

Do you mean something like this?

 Quaternion qBase = Quaternion.identity;
 qBase = Quaternion.Inverse(child.rotation);
 parent.localRotation = qBase * child.rotation;


I can't get that working either, and i don't see anything called Gyro.quat anywhere unless you mean attitude?

avatar image JC_SummitTech TSI25 · Jun 05, 2017 at 07:42 PM 0
Share

I do not understand why you change your parent rotation based on your child rotation. Gyro.quat is just pseudo code. it's whatever your current orientation is, attitude would be an option, but like I said before you probably want to filter the results.

avatar image TSI25 JC_SummitTech · Jun 05, 2017 at 07:46 PM 0
Share

well the child's rotation is the current orientation that i want to recenter, but if i just set it's rotation directly itll get re-updated to whatever the gyro thinks it should be on the next frame and no longer be recentered.

Because of that my goal is to offset that child's parent to the inverse of the child's rotation so that they cancel and the child is effectively facing forward again

Show more comments

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

How to get Angle float of specific axis.(Turret clamping related). 2 Answers

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

[OAFAT]Why does transform.rotation.x = 45 not work 3 Answers

Apply game object rotation using relative VR controller rotation? 2 Answers

How to check for NaN 4 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