Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 3 · Mar 05, 2013 at 12:38 AM · cameraiosquaternionaccelerometergyroscope

Why is the Gyroscope inverted?

Here is a script I got online, it works pretty well I just had to make a few edits, it could be a little smoother, but still. The main problem however, is that it is completely flipped. When I tilt it upwards, it moves the camera left. When I tilt it downwards, it goes right. When I move it right, it goes up, and vice versa. Tilting works correctly though. Any help would be greatly appreciated.Thanks:

 // iPhone gyroscope-controlled camera demo v0.3 8/8/11
 // Perry Hoberman <hoberman@bway.net>
 // Directions: Attach this script to main camera.
 // Note: Unity Remote does not currently support gyroscope.
  
 private var gyroBool : boolean;
 private var gyro : Gyroscope;
 private var rotFix : Quaternion;
 public var fpc : GameObject;
  
 function Start() {     
  
         Screen.orientation  = ScreenOrientation.LandscapeLeft;
        
         var originalParent = transform.parent; // check if this transform has a parent
         var camParent = new GameObject ("camParent"); // make a new parent
         camParent.transform.position = transform.position; // move the new parent to this transform position
         transform.parent = camParent.transform; // make this transform a child of the new parent
         camParent.transform.parent = originalParent; // make the new parent a child of the original parent
        
         gyroBool = Input.isGyroAvailable;
        
         if (gyroBool) {
  
                 gyro = Input.gyro;
                 gyro.enabled = true;
                
                 if (Screen.orientation == ScreenOrientation.LandscapeLeft) {
                         camParent.transform.eulerAngles = Vector3(180,90,180);
                 } else if (Screen.orientation == ScreenOrientation.Portrait) {
                         camParent.transform.eulerAngles = Vector3(90,180,0);
                 }
                
                 if (Screen.orientation == ScreenOrientation.LandscapeLeft) {
                         rotFix = Quaternion(0,0,0.7071,0.7071);
                 } else if (Screen.orientation == ScreenOrientation.Portrait) {
                         rotFix = Quaternion(0,0,1,0);
                 }              
         } else {
                 print("NO GYRO");
         }
 }
  
 function Update () {
         if (gyroBool) {
                 var camRot : Quaternion = gyro.attitude * rotFix;
                 transform.localRotation = camRot;
                 var direction : Vector3 = camRot * Vector3.up;
                 direction.y = 0;
                 gameObject.Find("print").guiText.text = direction.ToString();
                 //fpc.transform.rotation = Quaternion.LookRotation(direction);
                 }
 }
Comment
Add comment · Show 2
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 ByteSheep · Mar 05, 2013 at 12:51 AM 0
Share

Well it depends on how you hold the device, whether you are holding it in portrait mode or in landscape mode.. The lines:

 if (Screen.orientation == ScreenOrientation.LandscapeLeft) {
   camParent.transform.eulerAngles = Vector3(180,90,180);
 } else if (Screen.orientation == ScreenOrientation.Portrait) {
   camParent.transform.eulerAngles = Vector3(90,180,0);
 }

This part of the code is controlling the cameras rotation.
In your case the camera is rotated 90 degrees, try changing the Vector3 values and test the game again.
The other thing you want to look at is:

  Screen.orientation = ScreenOrientation.LandscapeLeft;

You can change this to portrait mode if you need to

avatar image 3 · Mar 05, 2013 at 02:02 AM 0
Share

That didn't seem to do much, $$anonymous$$aybe I'm not getting the correct vector numbers?

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

11 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

Related Questions

Match Object (Main Camera) To Gyroscope Rotation Rate 1 Answer

What is the best way to steer the direction of a sphere in 3D space on an iPad? 0 Answers

3D camera relatively using gyro a la N.O.V.A. 2 0 Answers

Sensor Fusion of Accelerometer and Gyroscope 0 Answers

How do I access CoreMotion and the Android equivalent? 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