How do I check the "shake sensitivity"

Get help using Construct 2

Post » Wed Apr 30, 2014 6:39 pm

hello construct2 fellas,

i want to detect if the user is "shaking" the mobile device, like for shaking cards.
Using the accelormeter built it wont work, because if hold the mobile device for example at 45degrees on the X-axe, the X-acceloremeter just keeps its current value.

Is there a build in function to get the delta? Otherwise i'd maybe write my own plugin or script to detect it with acceloremeterDeltaX and some threshold value - or does there exist such an event? well, thanks :)
Posts: 18
Reputation: 263

Post » Thu May 01, 2014 5:27 pm

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.
You do not have the required permissions to view the files attached to this post.
Posts: 18
Reputation: 263

Post » Tue Apr 07, 2015 10:42 pm

@wolfomat would you care to share a capx? im really having trouble setting it up!

Thanks so much for the explanation anyways! :)
Posts: 542
Reputation: 9,181

Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 20 guests