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
1
Question by naren596 · Feb 06, 2015 at 11:45 AM · androidunity 4.6accelerometer

Input.accelerometer x,y,z always returning zero

Hi, I am creating a simple game to achieve first person control on my android device HTC one M8. I started with joystick and could successfully move in FP. I tried in many ways with accelerometer but it seems Input.accelerometer x,y,z are always zero. I tried it on couple of other android devices but in vain. Player is in center of a room where camera is child of player. Fps is a component of player.

I am new to Unity, am I missing to add something as I could see unity games on my own device with First person control. I am using unity 4.6.2. Any help on this topic will be highly appreciated.

Here is the code I am trying, player is moving back

function Update() {
var dir : Vector3 = Vector3.zero; dir.x = Input.acceleration.x; dir.z = Input.acceleration.z; if (dir.sqrMagnitude > 1) dir.Normalize(); dir *= Time.deltaTime;

 if(Input.acceleration.x != 0){
       thisTransform.Translate (dir.x, dir.z, 0);
 }else{
     dir.x = -0.01f;
     thisTransform.Translate (dir);
 }   

}

Comment
Add comment · Show 7
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 ironblock · Feb 06, 2015 at 12:19 PM 0
Share

have you set the sensitivity in edit > project settings > input? otherwise this should do the trick. float dirX = Input.acceleration.x; float dirZ = Input.acceleration.z; transform.Translate (dirX, dirZ, 0);

avatar image naren596 · Feb 06, 2015 at 01:08 PM 0
Share

Thanks for the reply. I checked the sensitivity and code I am using is similar to the suggested code. Player is moving back suggesting that acceleration values are zero.

avatar image ironblock · Feb 06, 2015 at 01:19 PM 0
Share

do you have onscreen feedback of the accelorometer ? and its smart to clamp the player. maybe it moving extremely fast.

avatar image naren596 · Feb 06, 2015 at 01:25 PM 0
Share

I didn't add any onscreen feedback for now but I tested in many ways all leading to same conclusion that the values are zero. I will learn and create onscreen feedback and get back to you.

avatar image ironblock · Feb 07, 2015 at 11:26 AM 0
Share

just fill a gui or a mesh text with the accelorometer values. http://docs.unity3d.com/ScriptReference/Text$$anonymous$$esh.html

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by smoggach · Feb 06, 2015 at 04:07 PM

Go to edit->project settings->player and make sure that Accelerometer Frequency in the Other Settings section isn't set to "disabled".

Comment
Add comment · Show 5 · 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 naren596 · Feb 06, 2015 at 04:18 PM 1
Share

unfortunately accelerometer frequency is not an option in player settings when building for Android. I already checked for it in Unity 4.6.2 which I am using.

avatar image smoggach · Feb 06, 2015 at 04:20 PM 0
Share

Then chances are you'll have to do something to your manifest file in order to activate the accelerometer. Any android developers know the answeR?

avatar image naren596 · Feb 06, 2015 at 04:35 PM 0
Share

As far as my experience in Android is concerned, adding accelerometer in manifest is not a necessity unless we intend to publish to app store which is used for filtering devices. Usually sensory hardware is accessed by registering a listener if it exists which is identified using sensor manager. I don't think this is the problem.

avatar image ironblock · Feb 07, 2015 at 11:25 AM 0
Share

i dont think its a manifest problem. you can simpely check if it is by removing it.

avatar image joonturbo · Apr 14, 2017 at 12:33 PM 0
Share

I was developing on Android, and using Cloudbuild to build for iOS. This setting is invisible in my editor, but you can go into ProjectSettings>ProjectSettings.asset and find accelerometerFrequency: 0 and set it to 30 or 60

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Sensor Fusion of Accelerometer and Gyroscope 0 Answers

(Android) TouchScreenKeyboard isn't showed up when i clicked InputField in Unity 4.6.1p2 1 Answer

Runtime terrain loading, Partial terrain loding 1 Answer

How do I access CoreMotion and the Android equivalent? 0 Answers

Can you get the height that you are holding the phone? 2 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