• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

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

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

Calculate Angular Velocity to Match Remote Position 0 Answers

Camera Scrolling just track the Charakter if z-Rotation=180 0 Answers

iBeer/Liquid Type Effect - iOS 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges