Different Jump size on Android Unity 5 devices

Asked

Viewed 123 times

0

I created a game like Infinite Runner that works properly in the Unity 5 Game tab but in android when I perform Jump in my character it has a climb always of different size, how can I solve this problem?

OBS: The app was tested on 2 different Androids (4.4.2 and 5.0) (had the error in question).

Functions that perform 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));
        }
    }
}
  • I did a search and from what I saw may be related to the framerate tries to take a look

  • Where is defined jumpPower? Does its value change somewhere? And the function UpdateColliderScenarioPosition, what does it do? Why does it receive a fixed parameter with the value 0.37? Without these details, it is difficult to know where there can be an error.

  • Anyway, you’re mixing physics with frame rate management. Unity already does this for you when you use physics. Try to get the * Time.fixedDeltaTime multiplication by the force of the leap.

  • @Luizvieira jumpPower is defined by the inspector (2500f), it does not change during the game, Updatecolliderscenarioposition so that the collider jumps and does not crash with the barriers of the set.

  • @Luizvieira without the * Time.fixedDeltaTime the character goes off the screen, to solve I downloaded the jumpPower to 250 ma continuously exiting the screen (in the Unity editor tab jumps at the appropriate height with 250 in jumpPower)

  • @Luizvieira to stay with a suitable height on Android (4.4.2 and 5.0) changed the jumpPower to 50 however there is still an inconsistency of high heels

  • I got it. Well, you did put one Debug.Log before the line that adds force? Perhaps in the real device it is being called many times in a row, adding more force than the intended?

  • Do the elements appear in the same place on the device and in the editor? Is it just the jump that is in trouble? The problem must be related to the resolution, giving the feeling that the jump is higher or lower. What resolution is set in the editor (At the top of the game tab, there is a select with several options) and what is the device resolution?

Show 3 more comments

2 answers

1


To solve such a problem it is necessary to make two changes:

1) Change jump condition to:

if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)

so that the jump action only happens once (at the first instant the screen is played).

2) Remove the Time.fixedDeltaTime so that the height of the character’s jump is always constant.

0

When using the drive within Unity using its Physics, it is not necessary to use the "Time" Class to multiply the processor value. In your case try to remove "Time.fixedDeltaTime".

  • You’re absolutely right. But, your answer would only be really good if you explained it too why this is not necessary. If you make this explanation right, you get my +1 (even if AP you have mentioned in comments that this fix did not solve his problem).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.