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 /
  • Help Room /
avatar image
0
Question by Icewing726 · Sep 05, 2018 at 12:26 AM · quaternionmathgyroscopegyro

Rotate a Quaternion

I'm hitting a brick wall right now and it's really discouraging (is there any other kind?). Anyway here's my issue. I've made a very simple script that ties my gyro to my camera. It rotates as expected with one flaw, it starts at an unintuitive offset.


I consider my phones camera to be the direction I'm looking in. However when the game starts Phone Camera down corresponds to game camera forward.


I'm going to paste my code in along with a comment showing how I tried to rotate the quaternion. Here's some things I've tried:


  1. Multiply by (0,1,0,0) and all kinds of variations using the sin(x/2) with no luck. It seems like it only flips 180 degrees or nothing at all. I need a rotation of 90 around the y axis (which I realize is slot 3 or I think I realize that)

  2. I tried to rotate it with euler angles which worked for some rotations but yielded unexpected motion in some areas

  3. I tried rotating the quaternion around an axis, I was able to get it to face the correct direction by rotating it 90 about vector.left but then roll became yaw and visa versa and I couldn't fix it again.

  4. I've also tried setting other vectors as forward with no luck.


Can someone please tell me what I'm missing? The only alternative I can think of is to rotate the game world by 90 degrees and I'd honestly rather just turn off the comp and go drink rather then mess with that right now.

PLEASE TAKE THE CODE BELOW WITH A GRAIN OF SALT. I'M USING IT AS A TEST SCRIPT AND REALIZE IT HAS SOME UNNECESSARY PORTIONS.

 using UnityEngine;
 using System.Collections;
 
 public class HeadController : MonoBehaviour
 {
     public bool IsGyroAvailable;
     void Start ()
     {
         Screen.sleepTimeout = SleepTimeout.NeverSleep;
         //Need to spruce this up a bit, if gyros aren't present we need to update with a combo of accelerometers and compass inputs
         if (1== 1)
         {
             Input.gyro.enabled = true;
             IsGyroAvailable = true;
         }
         else
             IsGyroAvailable = false;
     }
     
 
     void Update ()
     {
         if (IsGyroAvailable)
         {
             this.transform.localRotation = Input.gyro.attitude;
             //this.transform.rotation *= Quaternion.AngleAxis(90, Vector3.up);
           //  this.transform.rotation *=Quaternion.Euler(90f, 0, 0);     
             //this.transform.rotation*= *=new Quaternion(0, 1, 0, 0);
            
             
         }
         else if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
         {
             Vector2 TouchDelta = Input.GetTouch(0).deltaPosition;
             transform.Rotate(TouchDelta.y / 2, -TouchDelta.x / 2, 0, Space.Self);
         }
     }
 }









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

156 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

Related Questions

Get single axis from gyroscopic input (iOS) 0 Answers

How can I work out the orientation of my rotatable cube via script? 1 Answer

Ignore gyroscope yaw 0 Answers

VR without a headset!? 2 Answers

Rotate main camera using phone gyroscope with +Z-axis always aligned to North direction and +X-axis aligned to East direction 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