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 LennyBench · Apr 03, 2016 at 06:36 AM · androidmobileaccelerometer

Accelerometer Input Rotation Help

I'm making a mobile shooting gallery style game, where you use the accelerometer to aim the camera. Currently, the game works when the device is being held pointed down, instead of forward like you would hold it normally. I would like it to work when you are holding the device in this way. I've spent a couple of days now trying to figure this out, but after failing several times, I decided it was time to consult the forums.

Here's the code:

         a.SetFloat("Horizontal", -Input.acceleration.x);
         a.SetFloat("Vertical", -Input.acceleration.y);

in the animator, I have a blend tree to blend between the cannon pointing up, down, left, and right. Originally, this was because I had buttons to move the cannon and I wanted to limit the rotation, however now I still have it because it's the only way it seems to slightly work.

Also,

         a.SetFloat("Horizontal", Input.acceleration.x);
         a.SetFloat("Vertical", Input.acceleration.z);

works in terms of keeping the device pointed forward, however, looking left and right only changes when tilting the device, instead of turning it left/right.

So the question is, how do I make an object rotate according to the accelerometer?

Any help is greatly appreciated. Thanks!

Comment
Add comment · Show 5
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 Ali-hatem · Apr 03, 2016 at 09:48 AM 0
Share

provide your code & more info : portrait or landscape & i can't differentiate between pointed down & forward

avatar image LennyBench Ali-hatem · Apr 03, 2016 at 05:33 PM 0
Share

Landscape. And by pointing down, I mean holding your device so that the back of the device points to the ground, and forward is where the back of the device points forward, as if you were taking a picture. Code has been added.

avatar image Ali-hatem LennyBench · Apr 03, 2016 at 05:55 PM 0
Share

this is the animator code but cheek this short tutorial from unity with one line of code Accelerometer Input

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

72 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

Related Questions

Problem with Android platform 0 Answers

Is it possible to access the native step-counter on mobile platforms. 2 Answers

Mobile bloom kills performance 1 Answer

Limit Z axis rotation on main camera (BUG?) 0 Answers

How do I pause the accelerometer? 1 Answer


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