Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Mobile game work on Android but is lagging on IOS

Discussion in '2D' started by PixStudio, Feb 7, 2023.

  1. PixStudio

    PixStudio

    Joined:
    Jun 24, 2016
    Posts:
    3
    Hi everyone !

    I'm making a 2D mobile game and I have a problem that I can't resolved, the mobile game is working perfectly on editor but when i build my game on mobile (only on IOS phone) my caracter is laggy when I clic the screen to jump.

    I have a little cube who constantly move sometime to the right sometime to the left, my jump need to be a continuous jump so I use Input.GetKey this allow the cube to jump everytime his ground whith the first screen clic.

    So this is how i do to move and jump my cube :

    Code (CSharp):
    1.  
    2.     private void Update()
    3.     {
    4.         if (Input.GetKey(KeyCode.Mouse0) && isGrounded)
    5.         {
    6.              jumpForce = 22f;
    7.              letsJump = true;
    8.         }
    9.     }
    10.     private void FixedUpdate()
    11.     {
    12.         if (letsJump)
    13.         {
    14.             cubeRB.velocity = new Vector2(0, 0);
    15.  
    16.             // I tryed with velocity jump and velocity move
    17.             cubeRB.velocity = cubeRB.velocity + Vector2.up * jumpForce;
    18.  
    19.             // And I tryed with AddForce jump and AddForce move, also a mix of them
    20.             //cubeRB.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
    21.  
    22.             letsJump = false;
    23.         }
    24.         if (canMove)
    25.         {
    26.             // Velocity move
    27.             cubeRB.velocity = new Vector2(speed * direction * Time.deltaTime, cubeRB.velocity.y);
    28.  
    29.             // AddForce move
    30.             //cubeRB.AddForce((new Vector2(direction, cubeRB.velocity.y) - cubeRB.velocity)
    31.                * speed * Time.fixedDeltaTime);
    32.         }
    33.     }
    34.  
    I have search a lot of things and tryed to find a solution but none works.

    I tryed :
    Application.targetFrameRate = 60;
    And
    Vsync count -> Don't sync in project settings
    And
    Fixed Timestep default with 0.02 and try to reduce at 0.01 and 0.005

    I have follow this for optimize my game performances :
    https://forum.unity.com/threads/unity-game-lagging-on-android-device.727145/

    But the problem still persist...

    Here a short video for better comprehension of my problem :

    https://www.youtube.com/shorts/pRmPmYFNk7A

    Notice this doesn't happen on every jump, when I tap the screen once I don't get lag most of the time, it's usually when I keep tapping the screen that it does.

    And As you can see in the video there is automatic jump with purple bumper using the same jump method (turn letsJump to true with highter jumpForce) and for this I don't touch the screen and the jump is perfectly fluid.

    On the video it's looking smooth but when I play it's very embarassing

    Image of performance on Iphone after I jump severals time the game get 60 fps and can drop to 50/40 fps when i jump.



    It's working perfectly on Samsung S10e and It's lagging on Iphone 14 Pro

    Any kind of help will be greatly appreciated.

    *Using 2021.3.2f1*
     
    Last edited: Feb 8, 2023
  2. gzckrg1

    gzckrg1

    Joined:
    Jun 24, 2020
    Posts:
    14
    I'm not sure if it's related to your problem but I think you should change Time.deltatime to Time.fixedDeltaTime on line 27
     
  3. PixStudio

    PixStudio

    Joined:
    Jun 24, 2016
    Posts:
    3
    Thanks for your reply, I tried changing deltaTime with fixedDeltaTime and the bug is still there, but I tried adding fixedDeltaTime to the jump with velocity on line 17. Now it's really better it lags a bit on some jump but not all. I noticed on the hud performance graph that the blue curve is not stable and the bug occurs each time there is a wave on this curve (when I click on the screen) I don't know what means Pre (curve name) and what might affect it