Touch. Shake device

Get help using Construct 2

Post » Mon Sep 16, 2013 7:35 pm

Ironically I was going to ask a similar question.

I experimented with a layout that shows X Y and Z output from the touch.accelerometerx, y , and z (without gravity - not sure of the difference) in three text fields, but the resulting data does into several decimal points. I suppose I ought to use an integer of the output?

FYI: X is left and right movement, Y is up and down movement, and Z is towards and away from you.

I see my users performing a left-right shake gesture, which will fill a progress bar and ultimately trigger returning to the original layout.

What I would like is any suggestions regards measuring the rate of change - from the X axis data. 4.0x seems to be a comfortable point, (and I don't want users to inadvertently fling their phones across the room). So - thoughts on measuring this accumulated 'shake' data?

Any input is welcome and appreciated!

- Scott
Posts: 12
Reputation: 760

Post » Sun Nov 03, 2013 4:43 pm

I've been experimenting with this a little. I'm currently unable to test on a physical device so I'd love some feedback, but everything seems to be working great in the simulator.

The basic idea is to check the X, Y and Z values (Acceleration) every so often (POLLINGINTERVAL) and compare to the last check to see if they've increased a significant enough amount (SENSITIVITY) and have also met a minimum acceleration (MINACCEL). I just created a group called Shake Detection, added some local variables to track the current values, global values to detect the previous values and some local constants to let me easily tweak things. To let my game know if I've detected any shaking I set the global variable IsShaking to 1. Here's a screenshot of my events/actions:

Looks like I can't post links yet, so add the http:// to the following "link" to see the image:

To use this, I just create another System Event (Compare Variable) and check if IsShaking = 1. If it does, the first thing I do is set IsShaking = 0 and do whatever action(s) I wanted.

This is just what I came up with. If anyone has any suggestions or tweaks, please let me know! Thanks!
Posts: 10
Reputation: 1,440

Post » Fri Mar 31, 2017 11:23 pm

Thanks a lot for this guide!
One question though: how would you determine the shake sensitivity?
In theory - i think - it should be something like dividing the current values with the last values but my problem are the negative values of the axis.

Can you help me out?
Hugs and greetings from this corner of the world.
Posts: 14
Reputation: 878


Return to How do I....?

Who is online

Users browsing this forum: AllanR, Artpunk, oosyrag, QuantumMMX and 9 guests