- Home /
How to judge intensity of shaking in android phones
Hi everyone. I am building a game and I need to know how fast a user is shaking his or her phone. The faster they shake the more points they will collect. Is there any special piece of code that would tell me this in Unity?
Thanking you in advance.
Answer by fafase · Jun 25, 2014 at 12:33 PM
Check the acceleration of the device, check how long before the polarity changes and that tells you how hard the guy is shaking.
Get acceleration axis
Is it different from previous
if no increase a counter return method
if yes, check counter value
if value too big shaking is too slow, counter to 0
if value small enough increase shakeValue, counter to 0
at the end of process if shakeValue is big enough, you won
Actually, step 8 may be discarded, considering that if the shaking becomes too low during the process then you put shakingValue down to 0. It would be a design decision.
Your answer
Follow this Question
Related Questions
Match Object (Main Camera) To Gyroscope Rotation Rate 1 Answer
Using custom accelerometer, gyro & magnetometer to move objects 1 Answer
Get absolute acceleration data from accelerometer/gyroscope but neglect rotational acceleration 1 Answer
How to get highest value for acceleration from Input.gyro 0 Answers
A node in a childnode? 1 Answer