I am creating an iOS game. It's my first experience in iOS. I am facing an issue in player movement. If the player moves in the real world this means the game object (character in the game) also wants to move. So I tried to access pedometer to take the step count. But it is not updating. It's showing the step count as 0 only. The value is not changing. Here's my script:

 private float loLim = 0.005F;
 private float hiLim = 0.3F;
 private int steps = 0;
 private bool stateH = false;
 private float fHigh = 8.0F;
 private float curAcc= 0F;
 private float fLow = 0.2F;
 private float avgAcc;

 public Text stepCountTxt;

 public void Update(){

 public int stepDetector(){
 curAcc = Mathf.Lerp (curAcc, Input.acceleration.magnitude, Time.deltaTime * fHigh);
 avgAcc = Mathf.Lerp (avgAcc, Input.acceleration.magnitude, Time.deltaTime * fLow);
 float delta = curAcc - avgAcc;
     if (!stateH) {
         if (delta > hiLim) {
             stateH = true;
     } else {
         if (delta < loLim) {
             stateH = false;
     avgAcc = curAcc;
     calDistance (steps);

 return steps;

void calDistance(int i){
  • \$\begingroup\$ What kinds of values are you seeing from curAcc and avgAcc over time? Also, note that your exponential moving average calculations are not correct, and will give varying results if your framerate changes. \$\endgroup\$ – DMGregory Sep 18 '17 at 13:02
  • \$\begingroup\$ Input acceleration. I think so. I am completely new to ios. I don't have any idea. I got this in Google but the result is negative. The game object want to move if the player walks in real world this is my target. If you know the solution please help me \$\endgroup\$ – Manoj Balaji M Sep 18 '17 at 13:27
  • 1
    \$\begingroup\$ If I had enough information to answer, I would. What I'm asking for are details on the symptoms so we can diagnose the problem. What numbers are you getting for curAcc and avgAcc? Try capturing multiple frames' worth of data and outputting them to a file to graph out — see what happens to the values during a step. That will tell us if you need a different threshold rule, or if this way of processing the acceleration is masking the steps. \$\endgroup\$ – DMGregory Sep 18 '17 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.