Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by bpalumbi · Apr 24, 2016 at 01:34 AM · c#iosvector3iphoneaccelerometer

How to Use Accelerometer to Move Object by Tilting Phone?

Hey, I'm working as part of a Hackathon. We are trying to make an iOS app for blind and visually impaired people. There are no graphics and your phone acts as a controller for the "rocket suit" that they player is in. We are using Unity to make a level to traverse. When the phone tilts forward, the player(which is just a sphere) should roll forward. The same for all the other directions. There are going to be a lot of audio cues as well.

Originally, we used the Unity documentation to build our accelerometer script, but that made the sphere too difficult to control. We tried to write our own. The link below is that code.

See my accelerometer controller

We are also using two other scripts. This first one is to control the sphere with just arrow keys in testing. We uncheck that when we run the game on a phone. Sphere Controller

The third one just links the camera to the sphere. The forums wouldn't let me post another link, but I don't think that is causing any problems.

The problem is that when the app is run on an iPhone, the game loads but nothing happens when the phone is tilted.

Please let us know as soon as possible if you know anything. We would really appreciate any help! The project is due tomorrow. Thanks!

accelerationcontroller.txt (602 B)
ballcontroller.txt (477 B)
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
2

Answer by ben-rasooli · Apr 24, 2016 at 05:51 AM

Simply add this script to your sphere or whichever object needs to use the accelerometer as a moving force:

 using UnityEngine;
 
 [RequireComponent (typeof (Rigidbody))]
 public class MoveController : MonoBehaviour {
     float speed = 10F;
     Rigidbody rb;
 
     void Start()
     {
         rb = GetComponent<Rigidbody>();
     }
 
     void FixedUpdate ()
     {
         Vector3 acc = Input.acceleration;
         rb.AddForce(acc.x * speed, 0, acc.y * speed);
     }
 }

Here, I'm using rigidbody to move the sphere, but you can also use transform.Translate() if you wish. The idea is just to read the accelerometer x, y and z values and feed them to your method.

Comment
Add comment · Show 2 · 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 BlastOffProductions · Sep 21, 2016 at 09:55 PM 0
Share

Thanks man! This really helps me out a lot! God bless : )

avatar image yurrr · Apr 27, 2017 at 09:55 PM 0
Share

This works. thanks!

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

161 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 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 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 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 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 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 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 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 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

How do I catch a low memory warning from iphone in Unity? 1 Answer

Is it possible to access the native step-counter on mobile platforms. 2 Answers

Unity Hanging when Changing a Vector3.x 2 Answers

How to play animation depending on distance ?? (Video) 0 Answers

Trying to Generate Different Random Values for Position of Game Object Instances [C#] 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