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 afrospacebuddha · Dec 01, 2015 at 11:29 PM · androidgyroscopetilt

calibrating a gyroscope controlled tilt platform(Android)

Hey y'all, so I am trying to make a platform tilt with gyroscope controls. When I load the game the platform is already tilted as my program seems to create a constant torque based on my phone's physical location relative to the y axis. I need to be able to set my phones returned location to (0,0,0) or create a torque that can oppose the constant movement of the phone so that these controls are more manageable. Any ideas?

     public class balance : MonoBehaviour {
         public float torque;
         public Rigidbody rb;
 
         void Start() {
         rb = GetComponent<Rigidbody>();
         }
         void FixedUpdate() {
         Input.gyro.enabled = true;
         rb.transform.Rotate(Input.gyro.attitude.x, 0, Input.gyro.attitude.z);
             }
 }



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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Sawula · Jan 02, 2017 at 12:07 PM

 using UnityEngine;
 using System.Collections;
 
 public class Gyro : MonoBehaviour {
 
     Vector3 rot_ini;
     public float _speed;
 
     void Start () {
         rot_ini = transform.rotation.eulerAngles;
     }
 
     // Update is called once per frame
     void Update () {
          transform.rotation = rot_ini + (new Vector3(Input.gyro.rotationRate.y,Input.gyro.rotationRate.z,-Input.gyro.rotationRate.x)*_speed);
     }
 }



Adjust the axis as needed in the new Vector3 I'm using this for my gravity but it should work for rotation

Comment
Add comment · Show 2 · 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 Petrit24 · Sep 09, 2019 at 02:10 PM 0
Share

When I put that code in my script, it says: Cannot implicitly convert type Vector3 to Quaternion. What is it that I need to change about the new vector3?

avatar image Sawula Petrit24 · Sep 16, 2019 at 03:08 PM 0
Share

Hey, sorry hadn't checked this in a very long time

Try changing every instance of "Vector3" to "Quaternion" Should work

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

42 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

Related Questions

Gravity on Android 1 Answer

How to detect the tilt angle of the mobile device on start? 0 Answers

Android - Gyroscope - When I hold still it, the camera continues to rotate 1 Answer

Inaccurate rotations with android phone gyroscope 0 Answers

Tilt scene using accelerometer/gyroscope 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