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 gamenovice · Jan 20, 2013 at 03:53 AM · androidglitchaccelerometer

Buggy Android accelerometer code

Hi all!

I need help regarding android accelerometers.

I am working on a bike game atm, and I have everything nice and setup, animation, physics, movement, etc. But there is one problem. I have the controls setup such that when you tilt your android device up or down, it moves forward, and left and right it turns. The problem lies in the turning mechanism. If I hold down the device at a corner for too long, it glitches out and stays stuck in that turning motion.

Here is the code for the control mechanism:

     public static float tiltThreshhold = .175f;
     public float moveSpeed = 4f;
     public float rotateSpeed = 3f;
     
     public static bool deadzone = false;
     
     
     private float panLimit = .9f;
     private float filter = 3f;
     public static Vector3 accel;
     
     public static float tiltCompare = .5f+accel.y;
     
     void Start () {
         accel = Input.acceleration;
         
     }
     
 
     
     // Update is called once per frame
     void Update () {
         Move();
     }
     
     void Move()
     {
             
             accel = Vector3.Lerp(accel,Input.acceleration,filter*Time.deltaTime);
             
             var accelerometerDir = new Vector3(0,0,.5f+accel.y*1.1f);
             
             var gravityDir = new Vector3(0,-5,0);
         
             var RotDir = new Vector3(0,accel.x,0);
             
             if(accelerometerDir.sqrMagnitude > 1) accelerometerDir.Normalize();
             
             transform.Translate(accelerometerDir*moveSpeed*Time.deltaTime);
             
         
             transform.Rotate(RotDir*rotateSpeed*Time.deltaTime);
             
             Debug.Log(accel.ToString());
         
     }

Please let me know asap! Also please let me know if I need to be more specific, or even show screenshots or video of what is going on. Thank you for your time

p.s. I am using unity 3.5 and due to financial reasons for licensing, wont be upgrading to unity 4 yet

Comment
Add comment · Show 1
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 gamenovice · Jan 20, 2013 at 06:07 AM 0
Share

upon further testing and research, I've been able to conclude one thing. The system works for a certain amount of time, but afterwards it glitches out. This is probably due to some weird issue where the accelerometer input is not being registered after that point. so the accelerometer works for 30 seconds maybe, but afterwards the system locks up and I can't use the accelerometer to move my bike. hopefully someone will be able to tell whats going on here

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

accelerometer speed 1 Answer

Player Movement when phone shakes 0 Answers

Android Glitch - random assets display after splash screen -1 Answers

android accelerometer left right 3 Answers

Weird double-tap bug when I use standart controller (Android) 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