Understanding AddForceAtPosition

Hello everyone,

As we all know, there is barely any information on this function. The documentation hardly explains how it works and there is not even one tutorial on it on the internet.

Anyway, I am trying to understand how it works. I don’t know if I am doing it correctly, but as “position” parameter, I am using the transform.position of the object I want to apply the force on.

rb.AddForceAtPosition(new Vector3(0,3,3), sphere.transform.position * 5, ForceMode.Impulse);

Now, if I got it straight, this should apply the force at the sphere’s center, right? So it would be like applying just AddForce. However, when I try this code, it applies a torque on the sphere.

Shouldn’t it be applying no torque at all, since I am applying the force on the center? I mean shouldn’t the object only rotate if I hit it either above or below the center of mass?

Once again, I trying to understand how the function works from the very beginning, so sorry if I am saying something stupid. I hope someone can clarify this for me.

AddForceAtPosition applies a force to a rigidbody at the given position.

There are some considerations:

  • The position is in world space, not in object’s local space. You may use Transform.TransformPoint por transforming a local position to world space.
  • The force is also specified in world space. You may use Transform.TransformDirection for applying a force in a direction relative to the object.
  • The method should be called within FixedUpdate. Applying it from Update might result in the force being applied multiple times per physics step, with unpredictable results.
3 Likes

Thank you for your reply! I will give it a try :slight_smile: