0 votes

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

in Engine by (15 points)

1 Answer

+1 vote
Best answer

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:

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".

by (3,298 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.