- Home /
Know if a device is shaking with the accelerometer
Hello! I'm making a script that shakes an object with the accelerometer. I've achieved this making a psudomovement. I've made an animation and when i shake my mobile (up or down) the animation plays, but it feels fake ^^' (because it is). The shake is only important in the Y axis, but can I know the velocity the mobile is shaking? I think the Input.aceleration.y value is the diference between the last position and the current.
To be clearly, I want an object that when i shake up slowly, it moves slowly (The direction i shaked) and when I shake up fastly, it moves fastly, and when im not shaking or the object has arrived to a max position, return to the center smoothly.
Thank you in advance!
You may find that Input.gyro.userAcceleration gives better shake detection than Input.acceleration - it tries to cancel-out the effect of gravity, so you can focus on the acceleration the player is applying.
Thanks for replying @D$$anonymous$$G, but in my device the value userAcceleration of the gyroscope is always set to 0,0,0 can be possible that not all the devices have gyroscope? :(
Answer by glenwatkinson · Jan 25, 2016 at 12:24 AM
A bit of an old post but make sure you call Input.gyro.enabled = true; at some point in your code.
Your answer

Follow this Question
Related Questions
Android Shake 0 Answers
Making a bubble level (not a game but work tool) 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Bullet not moving from script 3 Answers