Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Force and gravity not making sense. Everything multiplied by 50.

Discussion in 'Physics' started by TW27, Mar 2, 2016.

  1. TW27

    TW27

    Joined:
    Apr 24, 2015
    Posts:
    2
    I have looked and tested various things for about an hour and a half now and I just can't wrap my head around this. I am trying to strip away all the extra variables to understand gravity in Unity better, so I have a Kinematic Quad (Non-Moving Floor) and a Rigidbody Cube sitting on it. The Cube's mass is 1, and gravity is set to a nice round -1 on the y axis. Drag is 0.

    Using the code below, I adjust "thrust" to various levels. Using F=m*a, I reasoned that an upward force of 1 would prevent the cube from changing its velocity if it was already suspended in the air, and anything greater than 1 would cause it to accelerate upward. 1=1*1. When testing, however, I find that 50 is the amount of "thrust" or Force I need to balance the AddForce with gravitational acceleration, and that even 50.001 for the Thrust variable will cause my cube to accelerate upward very slowly.

    Can someone please help me understand where the "50" is coming from?

    Thank you in advance for taking the time to read and any help is greatly appreciated.

    Code (CSharp):
    1.  
    2.     void FixedUpdate() {
    3.  
    4.         if(Input.GetButton("Jump")){
    5.             rb.AddForce(0, thrust * Time.deltaTime,0);
    6.         }
    7.     }
    8.  
     
  2. oracnid

    oracnid

    Joined:
    Jun 1, 2013
    Posts:
    8
    Your physics step is probably 0.02 (i.e. 50 times per second), so deltaTime inside FixedUpdate() will be 0.02, i.e. thrust is being divided by 50.
     
    TW27 and hippocoder like this.
  3. TW27

    TW27

    Joined:
    Apr 24, 2015
    Posts:
    2
    This makes sense. Although even if the thrust is divided by 50, shouldn't it be the same effect if it is happening that many times per second? 1/50th of thrust * 50 times per second should put off the same force as gravity being -1 m/s per second. Is gravity not affected by deltaTime, and applied every physics step at the full -1 force?

    Thanks for your answer, this gives me more things to try and tweak when I get back home today!
     
  4. oracnid

    oracnid

    Joined:
    Jun 1, 2013
    Posts:
    8
    If you want to apply a force of 1 m/ss, then you would call AddForce(0, 1, 0) for the appropriate amount of time, i.e. 50 FixedUpdate() calls if it were for a second. At the moment you are applying 1 * Time.deltaTime = 0.02 m/ss continuously (i.e. every fixed update or 50th of a second) and therefore only applying a very small force as time progresses.

    Have you tried setting thrust to 1 and removing Time.deltaTime? Hopefully that is the problem.
     
    Last edited: Mar 3, 2016