Smooth Accelerometer movement

PortymanPortyman Member, PRO Posts: 409
edited November -1 in Working with GS (Mac)
Does anyone have a suggestion for smoothing out accelerometer movement.
I am controlling a car and can get it to move up, down , left and right, fine, but it is a bit jerky. I am using move control with stacked on. Any good ideas for moving diagonally ?

Comments

  • Rob2Rob2 Member Posts: 2,402
    You can get some goodish results playing around with low pass filters but GS will always be a bit glitchy and I doubt you will ever be able to get the silky smooth performance of a hand coded Objective-C app which uses OpengGL ES.
  • ericzingelerericzingeler Member Posts: 334
    I know this post is quite old, but here goes anyway.

    Smooth the accelerometer movement by averaging the input of an axis.

    Example:

    If we want to smooth the y-axis, we do the following:

    1. Create some variables or in GameSalad's case, Attributes. In an actor create the following (Real) attributes:

    AccelSmooth1
    AccelSmooth2
    AccelSmooth3
    AccelSmooth4
    AccelSmooth5
    AccelSmoothFinal

    2. Now in the same actor, create a group called "Acceleromter Smooth Group" to keep things organized. Within that group, drag in a constrain attribute behavior and set it as follows:

    Constrain Attribute: self.AccelSmooth1 to game.Accelerometer.Y

    Note: game.Accleromter.Y is located in Devices > Accelerometer.

    3. Drag in a timer behavior into the group and set it for .03 seconds. Now drag a constrain attribute behavior into the timer you just created and set it as follows:

    Constrain Attribute: self.AccelSmooth2 to game.Accelerometer.Y

    4. We need to repeat step three for self.AccelSmooth3, 4, and 5 as follows:

    timer: .06
    Constrain Attribute: self.AccelSmooth3 to game.Accelerometer.Y

    timer: .09
    Constrain Attribute: self.AccelSmooth4 to game.Accelerometer.Y

    timer: .12
    Constrain Attribute: self.AccelSmooth5 to game.Accelerometer.Y

    5. Ok, AccelSmooth1, 2, 3, 4, 5 attributes should be set at this point. Drag in Constrain Attribute into the group and set as follows:

    Constrain Attribute: self.AccelSmoothFinal to (self.AccelSmooth1 + self.AccelSmooth2 + self.AccelSmooth3 + self.AccelSmooth4 + self.AccelSmooth5)/5

    6. And your done. Use the AccelSmoothFinal attribute in place of game.Accelerometer.Y to give you a smooth y-axis input.

    Breakdown: You added a real time accelerometer reading + 4 other readings at .03 second intervals up to .12 seconds for a total of 5 different readings and divided them by 5. Pretty simple right?

    This may not be the optimal configuration and therefore you may want to play with the time and the amount of readings to maximize smoothness.
  • Rob2Rob2 Member Posts: 2,402
    sometimes its good to dig up old posts to see how things have developed, I will dust off my silky smooth accelerometer template which includes inertia :)

    edit: just read the rest of your post...how many constrains and timers is that in total then...!
    edit2: X axis ?
    edit3: I'll give it a try :)
  • ericzingelerericzingeler Member Posts: 334
    With inertia? Nice! I'd like to see that.

    I know, a bit much - 4 timers, 6 constraints. I'm sure reducing to 3 readings would be just about the same.

    Both the X and Z axis would be the same. Just replace game.Accelerometer.Y with X or Z.
Sign In or Register to comment.