add_central_force inconsistent behavior in 2D and 3D

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

The documentation of add_central_force says

Adds a constant directional force without affecting rotation.

From my understanding of the word ‘constant’ and from what I’ve read this should add a force to the RigidBody / RigidBody2D that remains forever until its removed.

So if you call add_central_force(Vector2(0,-10)) the RigidBody2D will be pushed upwards continuously, like a thruster. This is also what happens when I run the game.
But in 3D add_central_force(Vector3(0,-10,0)) seems to only apply a force for a single frame. I have to call it every frame to get the same effect.

So my question is: Is this intended behavior or am I missing something?

For better understanding, please see my example project

:bust_in_silhouette: Reply From: wombatstampede

Personally, I only use apply_impulse in 3D. Thinking also that applied forces run “forever” making it extremely difficult to reset them (especially if they are not applied at the center and therefore adding a torque force as well).

After your question I googled a bit. I assume that you’re using the Bullet physics engine (preferences). But basically it should be the same with the godot engine.

According to this (old) discussion:
https://pybullet.org/Bullet/phpBB3/viewtopic.php?t=1601

Forces are actually reset after each physics frame.

I propose that you use apply_central_impulse() instead in each _physics_process() or _integrate_forces() and scale (=multiply) your force with delta.

This leaves the question open why there are two different methods for force and impulse when each only apply for one physics frame? Honestly, I have no answer to this. If I repeatedly apply impulses in the lowest granularity the physics engine has (frame) then for me this adds up to a force. But perhaps there are aspects in the engine that distinguish even inside a physics frame between a 0-time “impulse” and a frame-time “force”.

Calling apply_central_impulse() every frame does have the I effect that I want but I still think that it is strange that add_central_force() behaves differently in 2D and 3D

Qendolin | 2019-05-25 21:50