Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    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:
    111
    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:
    22,214
    Probably because you're not performing the physics in FixedUpdate, where they only work properly.
     
  3. RicheyMB

    RicheyMB

    Joined:
    Jul 20, 2009
    Posts:
    111
    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:
    22,214
    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.