Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. If you're a macOS 10.13 High Sierra user take be sure to read this before updating Unity.
    Dismiss Notice
  5. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  7. Unity 2017.3 beta is now available for download.
    Dismiss Notice

iOS physics behaves differently in debug

Discussion in 'iOS and tvOS' started by RicheyMB, Nov 9, 2011.

  1. RicheyMB

    RicheyMB

    Joined:
    Jul 20, 2009
    Posts:
    109
    I am having a problem where I see a big difference in physics behaviour when debugging my code and deploying to iPad.

    I have a rigidbody and a trigger. The trigger handles a OnTriggerStay event and calls AddForce to the rigidbody. The force appears to be much greater when running on the iPad than it is on other platforms (Mac, Windows, WebPlayer).

    The only line of code in the OnTriggerStay event is
    other.rigidbody.AddForce(transform.forward * 2.5f, ForceMode.Force);

    Any suggestions?
     
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    20,405
    Probably because you're not performing the physics in FixedUpdate, where they only work properly.
     
  3. RicheyMB

    RicheyMB

    Joined:
    Jul 20, 2009
    Posts:
    109
    Doesn't appear to be the case FixedUpdate.

    I've altered the code to fill an array of objects that should have force applied at the next FixedUpdate. Then during the fixed update I apply the force to each object in the collection and then clear it.

    Everything is still handling the same way on other platforms but not the iPad?
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    20,405
    the only reason that it can possibly occur is if fixedupdate doesn't run in time (sub 10fps) or you're missing something in FixedUpdate ie doing math with the forces in Update() then passing the result to FixedUpdate. Because the math doesn't account for deltaTime*, you may have different physics once the number arrives to AddForce in fixedupdate.

    The reason I have focus on this is because debugging will slow down the CPU, leading to different results at different speeds of execution. The reason everything handles the same way on other platforms is because they're probably 60fps.

    *deltaTime should not be multiplied in FixedUpdate, as FixedUpdate works on a fixed loop.