Different sizes of jump when Android device

I created a game like Infinite Runner that functioning properly in the Game tab of the Unity 5 but on android devices when I do the Jump it’s never had the same height.

Note: App tested on Android 4.4.2 and 5.0
Note 2: Some values are added in inspector.

Functions that make the jump

void FixedUpdate () {
    CheckPlayerInGround();
    MakeJump();
    animator.SetBool("jump", !steppingDown);
}

void CheckPlayerInGround(){
    steppingDown = Physics2D.OverlapCircle(GroundCheck.position, 0.2f, whatIsGround);
}

void MakeJump(){
    if(Input.touchCount > 0){
        
        if((Input.GetTouch(0).position.x < Screen.width / 2) && steppingDown){
            if(slide == true){
                UpdateColliderScenarioPosition(0.37f);
                slide = false;
            }
            audio.PlayOneShot(audioJump);
            audio.volume = 0.75f;
            playerRigidbody2D.AddForce(new Vector2(0, jumpPower * Time.fixedDeltaTime));
        }
    }
}

If you want to get the same jump height every time, then you have to (simplifying)

  • apply the same amount of force
  • for the same amount of times / same period of time

every time you jump.

Right now you have at least 2 things in your code that might affect the jump height in different scenarios.

// this is basically your code 
void FixedUpdate() {
    if(Input.touchCount > 0) {
          playerRigidbody2D.AddForce(new Vector2(0, jumpPower * Time.fixedDeltaTime));
    }
}

As said in the API docs, touchcount stays the same throughout the frame. That means “from one Update() call to the next Update() call”. So that duration depends on your framerate

FixedUpdate() on the other hand runs n times per second. If your framerate drops, n FixedUpdates are simulated during 1 Update. As a result your code adds force n times depending on your frame rate whenever you touch the screen.

Another oddity that I’m spotting (although it shouldn’t be causing problems in your setup) is the force magnitude calculation

playerRigidbody2D.AddForce(new Vector2(0, jumpPower * Time.fixedDeltaTime));

If you want the jump to be of same height every time, then time shouldn’t be a factor in the calculation.
Of course Time.fixedDeltaTime is the same number every time (even Time.deltaTime is nowadays when used inside FixedUpdate() ) , but still I don’t think it should be a factor in the formula. If you’d now tweak your physics simulation rate, fixedDeltaTime would change and so would your jump height.

I know everyone always says “All physics stuff must be done in FixedUpdate”, but i think since your goal is to make a “one shot” event based on Input, go ahead and:

  • Move “MakeJump” inside Update() instead of FixedUpdate() so it only happens once per touch
  • Remove the fixedDeltaTime from the force calculation
  • Change the outer jump condition to something like if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) so that MakeJump only happens when the touch starts instead of happening every Update() as long as 1 finger is touching the screen.