Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

How Exactly does Rigbody.AddForce Work?

Discussion in 'Documentation' started by josieheartthrob, Apr 20, 2015.

  1. josieheartthrob

    josieheartthrob

    Joined:
    Feb 6, 2015
    Posts:
    8
    I kind of understand how to use Rigidbody.AddForce: changing the floating points in the vector3 variables changes how fast an object moves in the relevant direction. This is about how much the API explains, and it's adequate enough for a basic understanding of how to add a force to an object. But the API doesn't really explain how it works.

    So AddForce has a required Vector3 parameter that supposedly adds a force to the Rigidbody. But a Vector3 is just a point. How is the magnitude determined? Moreover, the ForceMode.Force page says "the unit of the force parameter is applied to the rigidbody as mass*distance/time^2." What does this mean? How is this applied to the rigidbody? Through the magnitude? Again, how is 'distance' determined? Is time 'Time.time'? Or is it some other predetermined variable.

    I know a lot of these questions might seem like common sense, but it makes it sooo much easier to understand if the API is thorough with it's explanations.
     
    AzatKhafizov likes this.
  2. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    No, a Vector3 is a set of three floats you can use for anything. X = force in the X direction and so on.

    I believe the physics engine is based on meters for distance and kilograms for mass.
     
  3. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    Hi,

    In general any point in three dimensions is a set of distances along the x, y and z axis from 0,0,0 to where point is.
    This set of distances is called Vector3. For a position, aka point, the x,y,z in the Vector3 describes the distance from 0,0,0 to the position.
    For a force the x,y,z describes the size of the force in each dimension. The description of the force itself has no "anchor" or point of reference.
    It is just a size in three dimensions. The different versions of the AddForce functions each have their own view of what the reference is for the Vector3 input.

    AddForce views the Vector3 input as being in world space. In Unity the Y axis means "up", so Vector3 (0, 1, 0) points "up" in world space. Calling AddForce (Vector3 (0, 1, 0)) will add an upwards force, in world space, at the center of mass of the rigid body.

    In contrast, AddForceRelative views the input Vector3 as being in the same orientation of the rigid body itself. So if a rigid body has been flipped upside-down then AddForceRelative (Vector3 (0, 1, 0)) will try to push the rigid body further down.

    You don't need to worry about the unit of force itself. The name for the unit of Force is Newton. You can read up on it here: http://en.wikipedia.org/wiki/Newton_(unit)

    A guideline for ForceMode is that Force and Acceleration are good at accumulating changes in velocity, like rocket boosters.
    Impulse and VelocityChange are good at immediately changing the velocity, like if you want to throw an item.
     
    steril, hopetolive and AzatKhafizov like this.
  4. josieheartthrob

    josieheartthrob

    Joined:
    Feb 6, 2015
    Posts:
    8
    So calling AddForce (Vector3 (0, 1, 0)) or (Vector3.up) will move the rigid body 1 unit up in the y axis every frame it's called? and the magnitude of Vector3.up is one unit because the default origin is at Vector3.zero?

    Can I suggest then that the AddForce API page explain this? So it says something like "Adds a force to the rigidbody which is determined by the Vector3 parameter's magnitude." and then maybe reference that a Vector3's magnitude starts at the origin. Or maybe explain that on the Vector3 API page? And it might sound redundant but I think it would be helpful to say that the force is applied for every frame it's called.
     
    AzatKhafizov likes this.
  5. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    The basic equation to remember where is
    • force = mass * acceleration, or
    • acceleration = force / mass
    the real answer sort of gets tricky because in order to comfortably tell how far an object will move when affected by a force, then you have to use calculus.

    You can roughly separate the changes in position, by whether or not the change is affected by the mass of the object
    • Force and Impulse are dependent on the object mass. So if you keep your input Vector3 fixed, but change the object mass, then the object will move slow or faster, even though you give the same Vector3 for Force or Impulse.
    • Acceleration and VelocityChange are independent of object mass. So it is only the Vector3 that determines how fast the object will move, aside from gravity.
    If you want to have some kind of reference for judging the values of these number, think of this. The default gravity we are using is pointing down with size 9.81, like Vector3 (0, -9.81, 0). The quantity 9.81 is an acceleration, not a force. The physics system adds this acceleration to every object at every frame. The physics system can add accelerations together, so if you add to an object the acceleration Vector3 (0, 9.81, 0) - this one is pointing up - then you will counteract gravity and effectively make the object "weightless". If you twice the amount, Vector3 (0, 2*9.81, 0), then you will effectively have made gravity point the other way.
     
    fuyca12, Rayeloy, hopetolive and 2 others like this.
  6. AzatKhafizov

    AzatKhafizov

    Joined:
    Dec 27, 2014
    Posts:
    3
    MortenSkaaning, josieheartthrob - thank you!
     
  7. frost4mage

    frost4mage

    Joined:
    May 4, 2019
    Posts:
    3
    I almost got it. but I think I need a more clean example to understand this thing.
    I have a rigidbody with its mass = 1 , use auto mass = unchecked and gravity is 2;
    how much it goes up when I add 20f force to it's Y position !?
     
  8. nqdduong31415

    nqdduong31415

    Joined:
    Jul 5, 2019
    Posts:
    1
    easy way to understand:

    Impulse = mass * velocity
    Force = mass * velocity * Time.fixedDeltaTime

    VelocityChange = velocity
    Acceleration = velocity * Time.fixedDeltaTime
     
    ggpereira likes this.