Search Unity

Mass, Force and linear drag

Discussion in '2D' started by Paragon99, Nov 25, 2013.

  1. Paragon99

    Paragon99

    Joined:
    Nov 23, 2013
    Posts:
    54
    I am having trouble understanding how these work with unity.

    I have a gameobjct. The game object has a Transform, Rigidbody2d, SpriteRenderer, Collider2d and script.

    The rigid body has a mass of 1 and a linear Drag of 0, it has no gravity, and IsKinematic is not selected.

    In the start function I have this.rigidbody2D.AddForce(new Vector2(5.0f,0.0f));
    I expect the velocity of the object to be 5 after 1 second, 10 after 2, and so on. However, End up with a constant velocity of 0.09999.
    (I have also tried it in the awake function with the same results.)

    In another test case, I have no force added in the Awake/Start function but in the update function I put
    this.rigidbody2D.AddForce(5.0f,0.0f);

    I expect an explosion of velocity... but it works more how I would expect it if it were called from the FixedUpdate function. (v(t=1)=5 v(t=2)=15, v(5=3)=30)
    Saying that, nothing happens if I use the FixedUpdate function, it seems to never be called.


    Also, at what point is the linear dampening applied to the game object? Is the dampening applied to the force or to the velocity? How is the dampening measured? I would expect the value to be 0 to 1 with 0 being no dampening, and 1 begin 100% dampening, thus an object with a dampening of 1 should not be able to move... and a dampening greater than one should begin pushing the object in the oppisite direction...

    How would i determine the terminal velocity of an object given it's mass, force and linear dampening?

    For example, m=1, d=0.5 and an update loop
    Update()
    {
    AddForce(5);
    }
    Terminal velocity = ??? (By experimentation this seems to be ~9.9
     
  2. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    Forces are not permanent, they are only applied for one physics frame. If you want it to be applied permanently, call the function every physics frame by doing so from FixedUpdate().
    Not usually a good idea, as Update is called with a varying frame rate and AddForce doesn't compensate for that. If you want to, you could multiply your force by Time.deltaTime/Time.fixedDeltaTime, and it will behave closer to how you want.

    This shouldn't be the case - FixedUpdate is usually the right place to do this from, and it should get called regularly, though not necessarily on every frame.

    The damping is applied to the velocity. I'm not sure what the formula is - I thought it was as you said, that it does something like: rigidbody2d.velocity -= rigidbody2d.damp * rigidbody2d.velocity; But I don't know for sure, and it looks like damp values greater than 1 do make sense, and 1 does not completely kill the existing velocity.

    You need to know the exact formula if you want to work out terminal velocities.
     
    Last edited: Nov 28, 2013