How would I smooth accelerometer input?

0 favourites
  • 3 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • 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:

    Unfortunately, it seems a small (but significant) port of Android phones give very touchy alpha values.

    Subscribe to Construct videos now

    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.

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

  • Try Construct 3

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

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

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