Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 SingerSilent · Oct 06, 2021 at 12:22 PM · gyroscope

How i can rotate a gameObject with the gyroscope of my phone?,I want to rotate a 2D gameObject using the gyrocope in the phone

Hello, I'm new with this but I want to rotate a gameObject 2D using the gyroscope of my phone, but it's not working, i try to convert the gyroscope data to vertor3 so i can use it in gameObject.transform.LocalRotation, please help me.

bool gyroEnable; Gyroscope gyro;

 UnityEngine.Gyroscope guro;

 public GameObject fishConteiner;
 

 float speed;

 Quaternion rot;

 Vector3 rotten;

 private void Start()
 {
     fishConteiner = new GameObject("fishConteiner");
     fishConteiner.transform.position = this.transform.position;
     transform.SetParent(fishConteiner.transform);
 }

 private void Update()
 {
     gyro = Input.gyro;
     gyro.enabled = true;

     rot = gyro.attitude;
     rotten = rot.eulerAngles;
     this.transform.rotation *= Quaternion.Euler(rotten);
 },Hello, I'm new with this so, i would like to know how i can make the gyroscope rotate my gameObject, I try to convert the quaternion to Vector3 so i can using with gameObject.LocalRotation, but it's not working, please help me.


bool gyroEnable; Gyroscope gyro;

 UnityEngine.Gyroscope guro;

 public GameObject fishConteiner;
 

 float speed;

 Quaternion rot;

 Vector3 rotten;

 private void Start()
 {
     fishConteiner = new GameObject("fishConteiner");
     fishConteiner.transform.position = this.transform.position;
     transform.SetParent(fishConteiner.transform);
 }

 private void Update()
 {
     gyro = Input.gyro;
     gyro.enabled = true;

     rot = gyro.attitude;
     rotten = rot.eulerAngles;
     this.transform.rotation *= Quaternion.Euler(rotten);
 }
Comment
Add comment · Show 6
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 Hellium · Oct 06, 2021 at 02:16 PM 0
Share

Why making things complicated??

Can't you simply

 void Update()
 {
      gyro = Input.gyro;
      gyro.enabled = true;
      transform.rotation = gyro.attitude;
 }
avatar image SingerSilent Hellium · Oct 06, 2021 at 05:43 PM 0
Share

No, because that only work for 3D objects, i want to use the gyroscope in 2D objects (a sprite), so i was trying to convert the quaternion to vector3 so maybe that way i can use that data in localRotation

avatar image Hellium · Oct 06, 2021 at 06:03 PM 0
Share

I can't test right now, but how about

 Vector3 eulerAngles = gyro.attitude.eulerAngles;
 eulerAngles.x = eulerAngles.y = 0;
 transform.eulerAngles = eulerAngles;
avatar image SingerSilent Hellium · Oct 06, 2021 at 06:23 PM 0
Share

I test it, but it doesn't work, maybe i'm forgetting something?, or the answer it's not in this way?, i don't know, but there must be a way, however thank you

avatar image Hellium SingerSilent · Oct 06, 2021 at 08:15 PM 0
Share

I've just tested my code and it works perfectly fine, the sprite rotates on the Z axis using the gyroscope.

Show more comments

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

168 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 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

Move sprite in Y based on phone tilt 0 Answers

Make character move up on Y axis as apposed to move forward in Z space when mobile device is tilted 2 Answers

Problems with gyro camera rotation. 0 Answers

Gyroscope controls ufo game? 0 Answers

About the 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