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(){
stepDetector();
}
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;
steps++;
}
} else {
if (delta < loLim) {
stateH = false;
}
}
avgAcc = curAcc;
calDistance (steps);
return steps;
}
void calDistance(int i){
stepCountTxt.text=i.toString();
}
curAcc
andavgAcc
over time? Also, note that your exponential moving average calculations are not correct, and will give varying results if your framerate changes. – DMGregory Sep 18 '17 at 13:02curAcc
andavgAcc
? 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. – DMGregory Sep 18 '17 at 13:53