Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bullet] Bullet physics PhysicsDirectBodyState.get_total_gravity() returns Vector3(0, 0, 0) in the first physics frame. #40314

Open
Tracked by #45022
54696d654a6f6c74 opened this issue Jul 12, 2020 · 2 comments

Comments

@54696d654a6f6c74
Copy link

Godot version:
Version 3.2.2 stable

OS/device including version:
GPU: AMD RX 580 driver - 20.4.2
OS: Windows 10 10.0.18363

Issue description:
This issue is physics related. In theory, adding a force equal to the weight of an object in the opposite direction of gravity should counteract the force of gravity, making it suspend in mid air.

However, in practice the objects gains a small but very noticeable upward velocity of 0.1633...
When this is done with using the state.get_total_gravity() to get the force to counteract gravity, everything works fine.

After printing both values (weight and total gravity's Y) their value is 9.8 and -9.8 respectively (for an object with mass 1)
The absolute values of these two variables are practically the same but they yield a different result.

Steps to reproduce:
Create an object with a RigidBody call add_central_force() with it's weight as the Y value.
Notice how the objects gains a velocity of 0.1633...
Then do the same with but inside the _integrate_forces() call, using the negative of the get_total_gravity() as the counter force.
Notice how the object is stationary (as expected).

Minimal reproduction project:
PhysicsExample.zip

@madmiraal
Copy link
Contributor

Actually, the problem is that in the first physics frame there is no gravity, state.get_total_gravity() returns Vector3(0, 0, 0); therefore applying a force of add_central_force(Vector3(0, weight, 0)) accelerates the body upwards for that one frame resulting in as subsequent constanct velocity of 0.163333.

Related to, if not a duplicate of #40127.

@madmiraal madmiraal changed the title Discrepancy between gravitational acceleration and weight Bullet physics PhysicsDirectBodyState.get_total_gravity() returns Vector3(0, 0, 0) in the first physics frame. Jul 12, 2020
@54696d654a6f6c74
Copy link
Author

Can confirm. After waiting for 1 frame before applying the force using weight, the object behaves as expected.

@pouleyKetchoupp pouleyKetchoupp changed the title Bullet physics PhysicsDirectBodyState.get_total_gravity() returns Vector3(0, 0, 0) in the first physics frame. [Bullet] Bullet physics PhysicsDirectBodyState.get_total_gravity() returns Vector3(0, 0, 0) in the first physics frame. Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants