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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Puzzling difference between running in Unity and running on iPad

Discussion in 'Editor & General Support' started by M4XXX, Nov 16, 2018.

  1. M4XXX

    M4XXX

    Joined:
    Aug 27, 2017
    Posts:
    10
    Hi,
    I'm very new to unity, (and first time poster) so may be missing something:

    I have a small game using 2d physics where I apply a force to a sprite that then rolls along a 2d physics hilly surface,
    Running inside Unity, it constantly accelerates and eventually jumps off the top of hills.

    But I built it for IOS and ran it on an iPad mini, and while it seems to run fine, the sprite doesn't accelerate as fast, and indeed doesn't go fast enough to reach the top of the hill!

    (When I ran it on the emulator for iPhone it never seemed to accelerate at all, just falling to the floor and sitting there)

    The only things I can think of are:

    a) The graphical resolution means on the iPad the sprite is more 'dense' and so a greater force would be needed to move it.
    b) The processor speed is somehow affecting the force - e.g. on the PC it is applying the force 144 time a second, on the iPad only 30?
    c) I'm doing something wrong.

    As c) seems exceedingly unlikely ...

    Here's the code from my Player...

    Code (CSharp):
    1.     private GameObject player;
    2.     private Rigidbody2D body;
    3.  
    4.     // Use this for initialization
    5.     void Start () {
    6.         player = GameObject.Find("Player");
    7.         body = player.GetComponent<Rigidbody2D>();
    8.     }
    9.    
    10.     // Update is called once per frame
    11.     void Update () {
    12.         body.AddForce(new Vector2(2, 0));
    13.     }
    14. }
    Any suggestions?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Update runs every frame, and should not be used for physics. You can't count on the framerate being consistent under any circumstances.

    --Eric
     
    M4XXX likes this.
  3. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    As mentioned, you probably want FixedUpdate instead of Update
     
    M4XXX likes this.
  4. M4XXX

    M4XXX

    Joined:
    Aug 27, 2017
    Posts:
    10
    Thanks @Eric5h5 and @JeffDUnity3D.

    I didn't get an email when you responded - so only just saw your replies. Thanks.
    I will give this a go!
     
  5. M4XXX

    M4XXX

    Joined:
    Aug 27, 2017
    Posts:
    10