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 Glitterpixie · May 14, 2013 at 04:36 AM · androidballaccelerometergyro

Desperate for help on control for a ball on android phone.

Hey guys. I'm completely new to unity and this is my first time using it.

I have a maze setup which I would like to roll a ball through.

After hours of searching all night I've been using this code which is the only one that finally made my ball move. However it flies off the screen and in all kinds of directions.

I read lots of posts pointing me to different places but I don't really understand the coding and therefore the explanations are useless to me.

Just wondering if anyone could point out if there is a mistake, I have a deadline coming up and need this completed asap!

Thank you in advance guys!

 function Update () {
     var dir : Vector3 = Vector3.zero;
     dir.x = -Input.acceleration.y*.5;
     transform.position.x += dir.x;
     dir.y = -Input.acceleration.x*.5;
     transform.position.y += dir.y;
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Glitterpixie · May 14, 2013 at 06:22 AM

Ok update on this. I've changed to try and use this code

 // Move object in XZ using accelerometer (home button at right hand)
 var speed: float = 2.0f;
 function Start(){
 }
  
  
 function Update(){
 var xmovment: float = -Input.acceleration.y;
 var zmovment :float = -Input.acceleration.x;
  
 Physics.gravity= Vector3(zmovment*5,-15,xmovment*5);
 
 }


However as was said in the same thread the ball gets caught on corners and sides and stops moving. It was said to update it with this code but I'm not sure where it fits in.

function Update(){ if (rigidbody.IsSleeping()){ print("Wake up little Suzy!"); rigidbody.WakeUp(); }

Any help would be great. Thanks guys!

Comment
Add comment · 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

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

13 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

Related Questions

Help with Android accelerometer 1 Answer

Jet Accelerometer Script 1 Answer

Help requested: Google VR / Phone rotation to gameobject. 1 Answer

Implementing the pedometer to count step with Unity3d 2 Answers

Anroid Gyro, Calling a function when phone is fliped once over. 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