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.
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.Sign up to join this community
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.
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.
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.