Search Unity

Question A Problem When Using Physics2D Simulated Freefall Movement

Discussion in 'Physics' started by HaiYangLiu, May 20, 2020.

  1. HaiYangLiu

    HaiYangLiu

    Joined:
    Mar 28, 2017
    Posts:
    4
    Hello!
    I found a problem when using physics2D. The ball simulated by physics2D never reached the height calculated by myself. It's like it uses a bigger gravity.
    I did a simple experiment to let the ball fall freely.
    the 2D gravity value in the editor is -10f
    the initial position of the ball is y = 0
    the rigidbody2d of the ball is Dynamic and Linear/Angular DragI is 0
    Fixed TimeStep is 0.02f
    I printed the speed and position of the ball in FixedUpdate and got the following data

    Frame = 0 Time = 0.0000 Pos = (0.0000, 2.0000) Velocity = (0.0000, 0.0000)
    Frame = 1 Time = 0.0200 Pos = (0.0000, 1.9960) Velocity = (0.0000, -0.2000)

    First look at the speed change.
    Vo=0
    V=Vo + gt = 0 + (-10f * 0.02f) = -0.2f. It is correct.
    h=1/2gt² = 0.5f * (-10f * 0.02f * 0.02f) = -0.002f. So the position at frame 1 should be 1.9980f instead of 1.9960f.

    Am I doing something wrong?
    Thank you!
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    This is the Box2D source code and this is the island solver portion which will be run in time-intervals that the physics system is set to controlled by Time.fixedDeltaTime (by default). There's nothing else going on beyond this.
     
  3. HaiYangLiu

    HaiYangLiu

    Joined:
    Mar 28, 2017
    Posts:
    4
    I found that the position difference is 0.002m per frame both in Physics2D and Physics3D(G is -10).
    I mean that the ball can fly 5m height by my calculated but only 4.5m in runtime.
    Is there any related settings?I thing my calculation formula is not wrong.What did Unity do?
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
    I already gave you that information above. What else do you need?