sharing is caring.
due to the good support and ideas i want to present my solution on this topic - all done with no extra plugins except for the Touch one and system events.
the deal is, to detect a "real" shake.
I'm using this import variables and constants(all other are just some mechanics for our game).
- deltaX: absolute delta from old acceleration to the new acceleration (+ / - not needed, as we don't need to know which direction).
- newAccelX: the current acceleration messured
- oldAccelX: the after the group we preserver the "newAccel" to this var, in order to get a good delta
- threshold: threshold is used for finetuneing. maybe you want to have an "aftershake"-effekt. to get a good value on this, you need to experiment a bit depending on your purpose.
- SHAKESTATIC: determines the "hardness" of the shake. with a higher value you will need to shake harder
Note that this is only for the X-Accelormeter, which is enough. i didn't expermine with Y/Z on this, but it's working as intended. so no need to add Y/Z.
you may notice the else block: there's a 0.8 seconds delay, which is another delay for an aftershake effect. its mostly used to play the "end"-shake value.
when the game is on the store, i'll notice you, so you can imagine a better way for what this whole thing is used.
just see the image for full details on that shaking.