Accelerometer Calibration: Beginner

Yes, I know that there are lots of other discussions out there about this problem. However, I've only been using this program for two months so I'm pretty new and don't understand the explanations that are given in the other discussions.

After a start button is pressed in my game, I want to set accelerometer.x and y to zero. I've created attributes called calibrated.x and calibrated.y that are set to 0. When start is pressed, I set both accelerometer.x and y to my created attributes. This was my failed attempt to calibrate.

So, if it's possible to explain to a beginner like me, can someone help me understand how to set accelerometer.x and y to zero from the beginning angle the user is holding the device at?

Any help is appreciated.

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited January 2018

    You can't set the accelerometer values. They are sensor-based. It's like saying you want to reset your pedometer to zero. Once you've walked somewhere, it's no longer going to be zero.

    What you can do is to refer to the original values. The way to do this would be to access the accelerometer value when the game starts and store this in a custom attribute such as game.startingX. You would do this by changing game.startingX to game.Accelerometer.X. Then when using the accelerometer values in your rules, you would instead use game.Accelerometer.X-game.startingX. And the same for Y or Z. So for example, if the game starts and game.Accelerometer.X is 0.5 but then the user tilts from 0.5 to 0.6, that would register as 0.1 of movement since game.Accelerometer.X would be 0.6 and game.startingX would be 0.5 (game.Accelerometer-game.startingX = 0.1).

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • trevorkbondtrevorkbond Member Posts: 6

    Holy cow you're a genius. Thank you

  • trevorkbondtrevorkbond Member Posts: 6

    @tatiang said:
    You can't set the accelerometer values. They are sensor-based. It's like saying you want to reset your pedometer to zero. Once you've walked somewhere, it's no longer going to be zero.

    What you can do is to refer to the original values. The way to do this would be to access the accelerometer value when the game starts and store this in a custom attribute such as game.startingX. You would do this by changing game.startingX to game.Accelerometer.X. Then when using the accelerometer values in your rules, you would instead use game.Accelerometer.X-game.startingX. And the same for Y or Z. So for example, if the game starts and game.Accelerometer.X is 0.5 but then the user tilts from 0.5 to 0.6, that would register as 0.1 of movement since game.Accelerometer.X would be 0.6 and game.startingX would be 0.5 (game.Accelerometer-game.startingX = 0.1).

    Sorry but I gotta bother you one more time. In my tilt rules I can't put game.accelerometer.x-game.starting.x as the first attribute, so I made a new attribute called tilt.x and constrained it to game.accelerometer.x-game.starting.x. I then put game.tilt.x into the rule but something about my math seems to be wrong. Any guesses? I might have other code that's messing me up.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    If you're using a Mac, you can change the rule condition to Numeric Expression and then open the expression editor to input those two attributes.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • trevorkbondtrevorkbond Member Posts: 6

    Sorry I'm just such a beginner at this stuff. It's working now! Thank you for the help.

Sign In or Register to comment.