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 /
avatar image
0
Question by jonathan.sant · Aug 20, 2011 at 12:02 PM · rotation3dmovingaccelerometer

Unity Realistic accelerometer controls

 Vector3 acc = Vector3.Zero;
 void update(){
     acc = Vector3.Lerp(acc, Input.acceleration, Time.deltaTime);
     transform.position = new Vector3(transform.position.x, (acc * -aVerticalRotation).x, transform.position.z);
 }

I have the above code to move my GameObject vertically (along the y-axis). This works fine except that I want the object to move relative to my motion i.e.

If I tilt the phone some X amount very fast it will move distance Z whereas if I tilt the phone with amount X but slower the distance will be A where Z > A.

I've tried to get the current reading subtracting it from the previous reading and multiplying it with the rest but apart from causing a jittery effect it didn't work exactly as I wanted it to.

Can some one help me achieve this ? I'm quite new to Unity.

Thanks

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
Best Answer

Answer by genetixsparkz · Aug 20, 2011 at 01:27 PM

from what i understand you basically want it so if you move really fast you impart some additional momentum to the object so it moves further.

your got a jittery affect because you multiplied by too high a number (basically you moved the mouse so great a distance in so short a time it skipped whole sections of the screen before being rendered again)

you could prevent this by doing addition instead such as

if current - previous <= 1 add 0 if current - previous <= 5 add 1 if....... all the way up to whatever is a max which doesnt cause jittering like else add 10

alternatly if you used an algorithm you could simply make sure the number returned by that wasn't too high if it was set a limit and redefine it to the max limit so for example if your old algorithm was

new_x = (current - previous) * old_x now you would add

if new_x > MAX_FOR_SMOOTH_TRANSITION new_x = MAX_FOR_SMOOTH_TRANSITION

finally if you really want to get complicated

read this paper on how microsoft made an algorithm for the mouse acceleration in windows. (which is basically what your doing)

http://msdn.microsoft.com/en-us/windows/hardware/gg463319

google windows mouse acceleration algorithm for greater detail

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 jonathan.sant · Aug 20, 2011 at 01:36 PM 0
Share

Good to know that my reasoning was correct after all. :) Good idea, thanks for the tips. I'll try it out and see how it goes.

avatar image jonathan.sant · Aug 20, 2011 at 01:53 PM 0
Share

Great my old algorithms is now working perfectly :) !!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Third Person Controller Rotation 0 Answers

How to change the forward direction of a player and make turning smoother 0 Answers

Using Accelerometer to move and rotate a 3d cube from left to right 0 Answers

How can I rotate my player with a Joystick? 0 Answers

Rotate towards movement direction 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