How would I smooth accelerometer input?

Get help using Construct 2

Post » Sat Apr 09, 2016 10:53 pm

I'm creating a simple game which rotates the players' view based on which direction they rotate their phone.

There's a demo here (just tap the three skulls to start).

I'm using the accelerometer alpha input (0-360) to move two identical images across the layout horizontally to create the loop and pan effect:

Image

Unfortunately, it seems a small (but significant) port of Android phones give very touchy alpha values. Here's a video of a Nexus 6P and a Sony Xperia next to each other running the same demo. The Xperia 'twitches' even in a resting state, and it's not the only device which does this.

I'm wondering how to approach 'averaging' these values without sacrificing too much of the response time to pan the screen. Although, I'm willing to sacrifice this quite a bit, since my game is more of a giant cutscene than an actual 'game'. How would you go about reducing this sensitively programmatically within Construct?

The most generic way I can think of would be to grab as many alpha values as possible over say 0.5 seconds, average them, and then tween the layout to the most recent 'average value'. Is this practical? I'm wondering if there's a better solution, or if my idea can actually work and not impact the performance greatly.
B
12
S
5
Posts: 28
Reputation: 1,558

Post » Sat Apr 09, 2016 11:01 pm

You might look into the lerp expression, it can be used to great effect for smoothing values.

Basically you will use lerp to move your screen a percentage amount towards the actual final values every tick. The result should be that the magnitude of movement is less the closer to the destination value your current value is, and greater the father it is.
Mistakes were made.
B
52
S
26
G
109
Posts: 1,606
Reputation: 61,633

Post » Sat Apr 09, 2016 11:08 pm

You can use a "dead zone" to prevent twitching. Have the screen movement event not run unless your input is greater than a minimum threshold away from the resting position. This will help you mitigate unwanted motion from rounding issues or small variations common to analog inputs.
Mistakes were made.
B
52
S
26
G
109
Posts: 1,606
Reputation: 61,633


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 37 guests