How do I check the "shake sensitivity"

1 favourites
  • 3 posts
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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).

    Vars:

    • 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.

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

    Thanks so much for the explanation anyways!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)