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 dare00 · Jun 30, 2014 at 11:16 AM · c#androidinputaccelerometer

why cant I get android accelerometer working in two planes?

Ive searched high and low to no avail! Im New to unity and as such am experimenting using android accelerometer to roll a sphere around my phone display. I found some code that seems to work for others, but for me I only get tilt in z axis (wrt display, x axis wrt main camera) but I require tilt motion control for left, right, back and forth. Probably something really simple i've overlooked, so feeling foolish in anticipation...

Any help will be greatly appreciated!

Here is essentially the code im using;

 Vector3 dir = Vector3.zero ;
 dir.x = - Input.acceleration.y ;
 dir.z = Input.acceleration.x ;
 if ( dir.sqrMagnitude > 1 )
 dir.Normalize();
 dir *= Time.deltaTime;
 transform.Translate ( dir * speed );

Comment
Add comment · Show 3
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 dare00 · Jun 30, 2014 at 09:49 AM 0
Share

Vector3 dir = Vector3 .zero ;

dir. x = - Input. acceleration . y ;

dir. z = Input .acceleration . x ;

if ( dir. sqr$$anonymous$$agnitude > 1 )

dir . Normalize();

dir *= Time . deltaTime;

transform. Translate ( dir * speed );

avatar image meat5000 ♦ · Jul 04, 2014 at 03:23 PM 0
Share

Using a HTC? You accelerometer may be broken, or needs calibrating.

That's 63 people who have potentially viewed your question looking to answer it :)

avatar image dare00 · Jul 05, 2014 at 07:52 PM 0
Share

can anyone see where im going wrong? dont get me wrong.. im not expecting to have my hand held atm but I am green lol

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Graham-Dunnett · Jul 04, 2014 at 03:10 PM

http://forum.unity3d.com/threads/roll-a-ball-with-android.184656/

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 dare00 · Jul 04, 2014 at 03:37 PM 0
Share

meat5000... im on a Sony c1505. I have considered calibrating the accelerometer since I get some weird things happening if, say, I hold the phone upright when loading the app.. methinks I need to zero it first, so thanks and ill keep it in $$anonymous$$d :-)

avatar image dare00 · Jul 04, 2014 at 03:37 PM 0
Share

lets see if I can post today.. big thanks to boredmormon and graham for ur help. ill see if that code solves my issue

avatar image meat5000 ♦ · Jul 04, 2014 at 03:57 PM 0
Share

Try

 Debug.Log(Input.acceleration);

This should show you if you have a hardware issue.

Also, consider this

http://docs.unity3d.com/ScriptReference/Gyroscope.html

Accelerometer is supposed to measure changes in position, literally the acceleration of the device. Gyroscope, in fact, is what shows you the orientation.

avatar image dare00 · Jul 05, 2014 at 06:38 PM 0
Share
  using UnityEngine;
     using System.Collections;
     
     public class tilty : $$anonymous$$onoBehaviour {
     
          //Use this for initialization
         void Start () 
     {
     var tilt : Vector3 = Vector3.zero;
         var speed : float;}
         private var circ : float;
         private var previousPosition : Vector3;
             
     @script RequireComponent(Rigidbody);
     function Start()
     {
         //Find the circumference of the circle so that the circle can be rotated the appropriate amount when rollin
         circ = 2 * $$anonymous$$athf.PI * collider.bounds.extents.x;    
         previousPosition = transform.position;
     }
             
     function Update (){
                 
         tilt.x = Input.acceleration.y;
         tilt.z = -Input.acceleration.x;
                 
         rigidbody.AddForce(tilt * speed * Time.deltaTime);
     }
             
     function LateUpdate(){
                 
         var movement : Vector3 = transform.position - previousPosition;
         c:\Users\DAVE\Documents\New Unity Project 3\Assets
 \tilty.cs: Error CS1519: Invalid token ';' in class, struct, or interface member declaration (CS1519) (Assembly-CSharp)        
         movement = Vector3(movement.z,0,  -movement.x);
         transform.Rotate(movement / circ * 360, Space.World);
         previousPosition = transform.position;  
         }}
         
         
         
         // Update is called once per frame
         //void Update () {
         
         //}
     //}
         

Added this code... got 5 error messages:

c:\Users\DAVE\Documents\New Unity Project 3\Assets\tilty.cs: Error CS1001: Identifier expected (CS1001) (Assembly-CSharp)

c:\Users\DAVE\Documents\New Unity Project 3\Assets\tilty.cs: Error CS1519: Invalid token ';' in class, struct, or interface member declaration (CS1519) (Assembly-CSharp)

c:\Users\DAVE\Documents\New Unity Project 3\Assets\tilty.cs: Error CS1002: ; expected (CS1002) (Assembly-CSharp)

c:\Users\DAVE\Documents\New Unity Project 3\Assets\tilty.cs: Error CS1519: Invalid token ';' in class, struct, or interface member declaration (CS1519) (Assembly-CSharp)

c:\Users\DAVE\Documents\New Unity Project 3\Assets\tilty.cs: Error CS1002: ; expected (CS1002) (Assembly-CSharp)

avatar image dare00 · Jul 05, 2014 at 07:55 PM 0
Share

Have tried tweaking.. no joy. i dont expect anyone to hold my hand thru this but i really am scuppered atm!!

avatar image
0

Answer by dare00 · Jul 12, 2014 at 03:06 PM

Ok I found this: http://u3d.as/content/unity-technologies/star-trooper/5fK and with some tweaking it does what I need! :-)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Constant Input.Accelerometer Updater for Mobile? 0 Answers

Touch Input with Event Trigger. How to handle with it properly. 0 Answers

Getting My Character to Move 1 Answer

How to calibrate my accelerometer? (available options not working) 0 Answers

Android Gyroscope not working ? 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