# Problems with input.acceleration to implement Shake

 0 I am trying to use the iPhones gyro to implement a shake feature. I particularly care about the direction of the shake.What I'm finding is "Input.acceleration" doesn't return a acceleration at all but an value corresponding to the tilt of the device.If you leave the device still but not level , you always get a reading. Hence, if I prop the device up you will find that either Input.acceleration.x or Input.acceleration.y comes back a consistent large value.A cut down example of the code looks something like this: ``````var dir : Vector3 = Vector3.zero; dir.x = -Input.acceleration.y; dir.z = Input.acceleration.x; dir *= 30; myObject.rigidbody.velocity += dir; ``````This is fine if I want a tilting type of control (above works quite well for that) but I'm after acceleration.Acceleration events I dont think will help me either.Ideas? more ▼ asked May 13 '12 at 02:17 PM Fabkins 675 ● 15 ● 20 ● 26 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

1 answer: sort voted first
 0 Now I've come to the acceptance that acceleration isnt acceleration at all but just the current tilt, the solution was pitfully simple. Acceleration is just the difference in tilt since the last reading.So the code looks something like this: ``````var dir : Vector3 = Vector3.zero; dir.x = - (Input.acceleration.y - lastA); dir.z = (Input.acceleration.x - lastB); lastA=Input.acceleration.y; lastB=Input.acceleration.x; dir *= 100; myObject.rigidbody.velocity += dir; ``````Now when I tilt the device I get an initial force in the direction I tilted but the force doesnt persist if I leave the device tilted at an angle. more ▼ answered May 19 '12 at 11:25 AM Fabkins 675 ● 15 ● 20 ● 26 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here