Search Unity

2D Physics Update Frequency

Discussion in '2D' started by batterj2-bb, Nov 20, 2013.

  1. batterj2-bb

    batterj2-bb

    Joined:
    Nov 5, 2013
    Posts:
    15
    Is there any documentation as to how the Box2D system is handled/updated? I think I'm getting some odd/erroneous behaviour from it.

    Below is a screenshot of our project - the pink line is supposed to represent where the player should travel through the level before it is launched, based on some simple calculations which worked in the 3D version of the game before we updated to 4.3. The grey line is a trail renderer drawn after the player has been launched. Not only does it not match where we've predicted the player to go (this may be a separate problem) but the curvature of the player's flight path does not appear to be correct (highlighted in the red square). At points after the player bounces of the mushroom it follows a curved trajectory as expected but then periodically picks up some force that alters the trajectory - the result being an almost sinusoidal trajectory, which makes no sense. My guess there is some conflict between the various timing systems which the game updates itself with.

    $Screen Shot 2013-11-20 at 10.52.15.png
     
    Last edited: Nov 20, 2013
  2. Kurius

    Kurius

    Joined:
    Sep 29, 2013
    Posts:
    412
  3. batterj2-bb

    batterj2-bb

    Joined:
    Nov 5, 2013
    Posts:
    15
    I thought it might be that as well but no joy. I have (I think) fixed it but I'm really not sure how (I'm not a fan of Unity, I'm being forced to use it - I'd rather be coding it from scratch) but it may have been a combination of physic material properties corrupting things. Reducing the friction down to zero provided predictable trajectories and, it would appear, smooth curves. However, I'm not convinced that was the whole solution.

    Other things I tried included:
    • Changing Update to Fixed Update (result: poor frame rate and no change)
    • Reducing drag coefficients (result: negligible if any)
    • Ensuring all colliders were to AABB to ensure perfect reflections (result: no change)

    It'd make sense if it dropped earlier than expected but its the rise of the trajectory that confuses me.
     
  4. mu-kow

    mu-kow

    Joined:
    May 15, 2012
    Posts:
    106
    Just looking at the picture makes me think that friction is what caused the reflection angle to be different and bounciness/restitution that increased magnitude of the reflection.
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,486
    2D physics updates at the same rate as the 3D physics. I'm not sure how you're affecting the 2D rigid-body but you will get a standard ballistic curve if you apply a force then allow a constant downward force (such as gravity) to work on it.

    The only thing I can guess is that you're constantly applying a force using "AddForce" per-frame rather than during fixed-update which would give you that variance? Total guess.

    It cannot be friction is it is not in contact with anything as far as I can tell so it's not part of the physics material. Even if you had linear/angular drag, it'd be constant and consistent.

    Maybe if you could provide a little more detail on what forces are being applied whilst it's in flight then I may have some insight for you. Alternately, report a bug and I'll look into it for you.