Skip to content

Commit 3a8264c

Browse files
committed
improve Body.applyForce docs
1 parent f7da964 commit 3a8264c

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

src/body/Body.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -801,15 +801,22 @@ var Axes = require('../geometry/Axes');
801801
};
802802

803803
/**
804-
* Applies a force to a body from a given world-space position for a _single update_, including resulting torque.
805-
* The position must be specified. Using `body.position` results in zero torque.
804+
* Applies the `force` to the `body` from the force origin `position` in world-space, over a single timestep, including applying any resulting angular torque.
806805
*
807-
* Forces create an acceleration that acts over time, so may need to be applied over multiple updates for the body to gain a visible momentum.
806+
* Forces are useful for effects like gravity, wind or rocket thrust, but can be difficult in practice when precise control is needed. In these cases see `Body.setVelocity` and `Body.setPosition` as an alternative.
808807
*
809-
* See also `Body.setVelocity` and related methods which do not require any time for acceleration to reach the given velocity.
808+
* The force from this function is only applied once for the duration of a single timestep, in other words the duration depends directly on the current engine update `delta` and the rate of calls to this function.
809+
*
810+
* Therefore to account for time, you should apply the force constantly over as many engine updates as equivalent to the intended duration.
811+
*
812+
* If all or part of the force duration is some fraction of a timestep, first multiply the force by `duration / timestep`.
813+
*
814+
* The force origin `position` in world-space must also be specified. Passing `body.position` will result in zero angular effect as the force origin would be at the centre of mass.
815+
*
816+
* The `body` will take time to accelerate under a force, the resulting effect depends on duration of the force, the body mass and other forces on the body including friction combined.
810817
* @method applyForce
811818
* @param {body} body
812-
* @param {vector} position
819+
* @param {vector} position The force origin in world-space. Pass `body.position` to avoid angular torque.
813820
* @param {vector} force
814821
*/
815822
Body.applyForce = function(body, position, force) {
@@ -988,7 +995,7 @@ var Axes = require('../geometry/Axes');
988995

989996
/**
990997
* A `Vector` that accumulates the total force applied to the body for a single update.
991-
* Force is zeroed after every `Body.update`, so constant forces should be applied for every update they are needed. See also `Body.applyForce`.
998+
* Force is zeroed after every `Engine.update`, so constant forces should be applied for every update they are needed. See also `Body.applyForce`.
992999
*
9931000
* @property force
9941001
* @type vector
@@ -997,7 +1004,7 @@ var Axes = require('../geometry/Axes');
9971004

9981005
/**
9991006
* A `Number` that accumulates the total torque (turning force) applied to the body for a single update. See also `Body.applyForce`.
1000-
* Torque is zeroed after every `Body.update`, so constant torques should be applied for every update they are needed.
1007+
* Torque is zeroed after every `Engine.update`, so constant torques should be applied for every update they are needed.
10011008
*
10021009
* Torques are converted to acceleration on every update, which depends on body inertia and the engine update delta.
10031010
*

0 commit comments

Comments
 (0)