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
6
Question by Caiuse · Aug 09, 2010 at 03:05 PM · controllercontrolaccelerometer

Using the accelerometer to move left and right on one axis

Hi there, I'm extremely new to UnityIphone and I'm trying to do something that I would consider very simple.

I'm trying to make a object 'strafe' left and right depending on the tilt of the accelerometer, I don't even want velocity to come into play, simply move left at a constant speed in tilted left, and visa-versa.

Thanks - Caius

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

2 Replies

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

Answer by Billamu · Aug 09, 2010 at 11:04 PM

var speed : float = 10; var moveThreshold : float = .2;

private var movex : float; private var iPx : float;

function Update() { movex = 0; iPx = iPhoneInput.acceleration.x;

 if (Mathf.Abs(iPx) > moveThreshold)
 {
     movex = Mathf.Sign(iPx) * speed;
     transform.Translate(movex,0,0);
 }

}

The variable moveThreshold is used so that your object will remain still when the device is upright and will only move when you lean the device enough.

Mathf.Sign() outputs a +1, 0 or -1, whereas Mathf.Abs() returns a positive number only.

http://unity3d.com/support/documentation/ScriptReference/Mathf.Sign.html http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

Comment
Add comment · Show 3 · 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 Caiuse · Aug 10, 2010 at 10:44 AM 1
Share

Thank you so much

avatar image faraioswald · Mar 23, 2016 at 01:56 PM 0
Share

Wow thanks so much man, just wat im looking for

avatar image stf940 · Mar 02, 2019 at 01:36 AM 0
Share

somebody tell me how to put this in my script. i try to copy but when i paste in scrip they don t work. scrip is going red help

avatar image
-8

Answer by dilmer · Sep 12, 2013 at 06:58 AM

Check out this control I wrote which may help you out.

Guys,

I worked in a game recently which needed an accelerometer control for a spaceship I created which is now available in the App Store as well, during my programming I found myself using this control for other games. I would recommended as is super easy to integrate into your game.

Download Now from the Asset Store

alt text

Comment
Add comment · Show 1 · 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 LoungeKatt · Mar 07, 2014 at 04:16 PM 8
Share

If you wanted to advertise, it would be better after showing you could at least attempt to answer the question. No point trying to hold back other developers for a few dollars.

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

7 People are following this question.

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

Related Questions

How to make camera position relative to a specific target. 1 Answer

Hey everyone. I need some help please. Does any of you know a Bike controller/physics tutorial? ,does anyone know any tutorials on bike movement and Physics? 2 Answers

controling an 3d object with touch screen.. 0 Answers

Giving individual players control of specific units in an RTS/MOBA 0 Answers

MMD How to export model and animations to Unity as 3rd person controller? 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