Search Unity

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

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    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

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    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.