Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
3D KinematicBody not affected by area gravity in Bullet Physics #15554
OS/device including version:
var state = PhysicsServer.body_get_direct_state(get_rid()) var gravity = state.get_total_gravity()
I thought I was able to do this before in the Bullet Physics engine but tested today and the gravity is just always
Steps to reproduce:
extends KinematicBody func _physics_process(delta): var state = PhysicsServer.body_get_direct_state(get_rid()) print(state.get_total_gravity())
If you switch the 3D physics to GodotPhysics it should print
Minimal reproduction project:
I ran into this on Linux as well and poked around the source to find the cause. Seems to be because the Bullet glue classifies it as a static body with no mass and Bullet doesn't compute gravity for rigid bodies with no mass. The way the Bullet built-in, and seemingly perpetually buggy,
I tried replicating the functionality in a GDScript using the
Of course, adding a pseudo-gravity vector to the final velocity vector on every frame (assuming you tune the gravity vector so it feels right) could work for some cases.
Any input from a more regular dev on what the desired outcome is or how to approach solving this? I'd like to start contributing and figure this could be a good issue to cut my teeth on.
I completely forgot this issue, and I will look on this soon.
@Dar13 Also in both engines (Godot and Bullet physics) the kinematic body gravity is not handled by engine since the kinematic body is meant to be moved "Manually".
So it has no sense to handle its gravity inside the physics engine, and it's care by the developer handle it.
This is the correct way to handle it, if you don't want control it just use a rigidbody in character mode.
Instead @LeonardMeagher2 is talking about the fact that is not possible to take the gravity "that should affect the kinematic body" from its state object. It's not so difficult to fix it.
I'll keep you updated
Alright, that's what I kept drifting towards while writing that comment.
I know you said you'd look at it, but I looked into it anyways as an exercise to get familiar with the codebase. Came up with the attached patch and tested it with both the given project and with an Area with space override set to "Combine" and the gravity changed accordingly.
If this seems acceptable to you, I can make a PR tomorrow.