Problems with input.acceleration to implement Shake

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?

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.