Offsetted add_force method turns the rigid body

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

Could someone please explain to me why offsetting a force vector initially perpendicular to the z axis turns the rigid body on the x axis, does it only offset the origin of the vector if yes how do I fix this issue?

Code in question:

add_force(thrust, $".".get_translation() + $"Submarine Rig/mast".get_translation())
:bust_in_silhouette: Reply From: wombatstampede

If you look here:
https://forum.godotengine.org/8529/how-to-properly-use-add_force-in-rigidbody-3d

Then you’ll see that the position is actual an offset in global coordinate space.

Personally I only use apply_impulse but I assume (also according to the old Godot 2.x related post above) that add_force works in a similar fashion. (Sadly, the docs are sparse for add_force).

You get the global offset for a child object like this:
$MyChild.global_transform.origin - global_transform.origin (I omitted the self. or $"." to the second global_transform adressing the “parent” itself as it is not needed here.)

Keep in mind that the force vector itself is in global space.

Here also some info about add_force by kidscancode:
http://kidscancode.org/blog/2017/12/godot3_kyn_rigidbody1/

If you run into problems here then consider using apply_impulse instead repeatedly from inside _integrate_forces or _physics_process. Multiply the force by delta so the multiple impulses add up to the force over a second. The advantage is that these impulses can be adjusted in position and direction every physics frame.

I also tried to post some info here. (It contains some text about apply_impulse but not add_force):
https://godotdevelopers.browse-tutorials.com/discussion/18480/godot-3d-vector-physics-cheat-sheet

1 Like