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 spiceboy9994 · Jan 09, 2014 at 07:36 PM · iosaccelerometeraccelerationinput.accelerationphysics.gravity

Input.acceleration throws "Index out of bounds"

Hi:

I have a game that alters Physics gravity by using the device accelerometer and other variables. So, I have something like this.

 void FixedUpdate()
 {
   //...
   DoUpdateGravity();
 }
 
 void DoUpdateGravity()
 {
    Physics.Gravity = GetGravity();
    //Do some stuff and apply gravity forces
 }
 
 Vector3 GetGravity()
 {
  Vector3 accel;
  #if UseDeviceOrientationForGravity
   try
   {
    //When my device is not moving, the following line throws and index out of range Exeption 
    accel = Input.acceleration.normalized;  
    /*this is the xcode detailed Error: 
    UnityException: Index out of bounds.
    at UnityEngine.Input.get_accelerationEvents () [0x00000] in <filename unknown>:0*/
   }
   catch (Exception ex)
   {
    accel = Vector3.Zero.normalized;
   }
   accel*= m_GravityForce;
   accel.x = -accel.x;
   
  #if TweakGravityVector
   float s = Mathf.Sin( m_TweakGravityVectorAngle );
   float c = Mathf.Cos( m_TweakGravityVectorAngle );
   Vector3 tmp1 = accel * c;
   Vector3 tmp2 = Vector3.right * ( 1 - c ) * Vector3.Dot( Vector3.right, accel );
   accel = Vector3.Cross( accel, Vector3.right );
   
   accel*= s;
   accel+= tmp1;
   accel+= tmp2;
  #endif 
   
   return accel;
 }

I'm using unity 4.3.2f1 and xcode 5.0 (this is an iOS Unity3d unity game). I don't know why I'm getting this error, but following code makes my character to shake as crazy, and the shaking increases over time. The weird thing is that on debug mode, the application does not break due the exception, the execution continues, just the shaking issue. After I placed the try catch, shaking stopped and exception was catched and handled, but my character does not respond to device tilting and shaking anymore. Any guidance on this issue?

Thanks a lot

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

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

18 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

Related Questions

Accelerometer differences by hemisphere? 0 Answers

Networking Accelerometer uses wrong axis 0 Answers

Accelerometer input working in Unity Remote, not working in build. 1 Answer

Using Mathf.Clamp with Accelerometer to control movement speed has slow response time, how can I smooth it out? 0 Answers

How to calibrate accelerometer according to start ? 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