-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Setting RigidBody global_transform into the _input
function fails.
#40486
Comments
That seems expected? You are not meant to be able to directly modify a RigidBody in this way. Never were. The "correct" way to do this, would be to suspend the physics processing of the body for 3 frames. And set the position on the second frame. |
You are not supposed to change a RigidBody's transform every frame (or even every few frames), that I can agree. I'm talking about one-time changes here, a way to teleport the RigidBody whenever it needs to be reset. Here's what the documentation says about this:
I'm honestly not convinced a simple reset would require pausing the physics (this could also introduce noticeable jitter in scenarios where you're teleporting a moving RigidBody that needs to keep moving after being teleported). I am perfectly fine with explicitly synchronizing with the physics processing though, as it does make more sense than randomly calling from an input event or a signal. |
@Cybolic can you also open an issue with a sample project that shows that your applied force is halved? |
This issue happens on Godot Physics too, and it was not an issue before because Bullet was 2 Physics Frame behind. CauseThe cause of this issue is a processing order, and it's a bit complex to explain. First, remember that the code that updates the
Note: it takes the transform returned by Node3D::get_global_transform and set it to When the input is fetched by this line https://github.com/godotengine/godot/blob/master/platform/linuxbsd/os_linuxbsd.cpp#L234 it triggers your The Look closely on this portion of the code:
for (int iters = 0; iters < advance.physics_steps; ++iters) {
uint64_t physics_begin = OS::get_singleton()->get_ticks_usec();
PhysicsServer3D::get_singleton()->sync();
PhysicsServer3D::get_singleton()->flush_queries();
PhysicsServer2D::get_singleton()->sync();
PhysicsServer2D::get_singleton()->flush_queries();
if (OS::get_singleton()->get_main_loop()->iteration(frame_slice * time_scale)) {
exit = true;
break;
} Notice that So once the To do a recap, the flow is the following:
The reason why it happens randomly is because the inputs sometimes is fetched by also |
_input
function fails.
This can be easily fixed by putting a transform flush at the start of the |
The halved force was a gut feeling, it was actually related to issue #40508: I was applying gravity in Thanks for the explanation about the flow of operations, I never took a look at this before so that's some interesting info to me. |
we're you applying gravity by setting the correctly adjusted linear velocity on the physics state? or we're you not using the provided state. in which case, yeah it wouldnt work. |
I'm using custom integration, so I'm applying gravity manually in var a := forces * state.inverse_mass + state.total_gravity
state.linear_velocity += a * state.step After a reset input, I would set the transform directly and also set the RigidBody's linear_velocity to zero (which does work), but from what @AndreaCatania said, only the transform part is ignored as it gets overridden. Just to be clear, I was getting twice the gravity because of #40508. |
Godot version:
3.2 custom build, issue bisected to commit e7d8464
OS/device including version:
Linux Mint 20
Issue description:
When setting the
global_transform
property of a RigidBody, the expected result sometimes happens, sometimes does not, seemingly at random.Steps to reproduce:
Add a RigidBody to a scene, add a script that sets its
global_transform
property following an input event, run the game and press the key to confirm whether the transform actually changes.Minimal reproduction project:
BulletGlobalTransform.zip
This project contains a workaround for the issue. First run the project and press space to reset the falling cube's position. Doing so should fail most of the time.
Open the RigidBody script and uncomment the yield line: now the transform should only be set during a physics update, and pressing space will always work.
Is this issue a regression or expected behavior following PR #40185?
This PR has also completely changed the behavior of my physics-based game (a drone simulator), with the drone getting its thrust more or less halved, even though thrust is calculated during physics frames only.
The text was updated successfully, but these errors were encountered: