2
\$\begingroup\$

Does the AddForce method continue add velocity to an object forever? Does it need to be limited by another line of code?

Sorry if it is too broad or too simple; I am completely new to programming and Unity, as well as 3D development.

\$\endgroup\$
3
\$\begingroup\$

AddForce will apply a force for the current update cycle. The force is applied to the RigidBody for that update cycle, then cleared. At the beginning of each physics step, the forces are zero. Then the forces for gravity, friction and calls to AddForce are summed up and added to the RigidBody.

Assuming the forces added to the object don't cancel each other out, there will be a resulting velocity change. If force is continually applied, the velocity can reach infinity. But unless you're applying infinite force, the force will not reach infinity, because it's applied and cleared each physics step.

You do not need to 'negate' a force after it's been applied to stop it from being applied.

\$\endgroup\$
  • \$\begingroup\$ @VictorMatheus A force applied instantaneously this way is referred to as an impulse. See also here. \$\endgroup\$ – Engineer Jun 11 '16 at 16:22
  • \$\begingroup\$ @Byte56, you said that "The force is applied to the RigidBody for that update cycle", then " At the beginning of each physics step, the forces are zero". Is physics step not happen in the beginning of update cycle? \$\endgroup\$ – PaulD Aug 31 '16 at 9:21
  • \$\begingroup\$ @asio The physics update cycle is a different update cycle than the regular update cycle. \$\endgroup\$ – MichaelHouse Aug 31 '16 at 13:52
1
\$\begingroup\$

Force is applied continuously along the direction of the force vector. Specifying the ForceMode mode allows the type of force to be changed to an Acceleration, Impulse or Velocity Change. Force can be applied only to an active Rigidbody. If a GameObject is inactive, AddForce has no effect.

Taken directly from here. Maybe read more on that website. It has some good answers.

\$\endgroup\$
1
\$\begingroup\$

It depends on how you add it. If you add it once on some callback, for example, or button press\release event, then it will be added once.

This once applied force, will affected by other things, like friction for example, which over a period of time will render that applied force value to zero (by decreasing it's every physics update).

If you apply it constantly in update function of your character controller, yes, you'll be adding force infinitely.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.