How to use add_force without having offset???

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By buxnast

I have a problem based on add_force. When I use it, object rotates and changes direction uncontrollably after reaching the given point. Please if you know a better way of moving rigidbody with working collisions, let me know.

:bust_in_silhouette: Reply From: Avantir

This is hard to answer with more information, so here’s the details.

Rigid bodies are physical objects that can move and rotate freely when they collide with other objects. By adding a force, you are causing both a movement and rotation, depending on where you apply that force to the body. If you apply it at the exact centre (Offset 0, 0), the force will cause movement, but no rotation, because the torque will be 0.

However, if the rigid body collides with anything during that movement, that will still cause the body to rotate. This can even happen if you move the rigid body along the ground, because the friction between the body and the ground will cause drag that makes the body rotate.

If you do not want your rigid body to rotate at all, consider either:

  1. Setting RigidBody.mode = MODE_CHARACTER. This will keep it as a rigid body, allowing you to provide forces and the physics engine to handle collisions, but the body will not rotate from any collision or force you apply.
  2. Using a KinematicBody instead of a RigidBody. Kinematic bodies work in movement vectors, not in applied forces. They will not rotate unless you explicitly tell them to. They will collide with other objects, but only in a simple way. Bouncing or friction, for example, won’t work unless you program those in manually.

Thank you for your answer. May I ask you, is there a way to still use a rigid body but also prevent it from ocilating forward and backward around the point?

buxnast | 2020-06-01 08:09