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

Fix kinematic bodies not synchronizing state when using Jolt Physics #101803

Merged
merged 1 commit into from
Jan 20, 2025

Conversation

mihe
Copy link
Contributor

@mihe mihe commented Jan 19, 2025

Fixes #101753.

Prior to #100983 we relied on a JoltBody3D::sync_state flag to indicate whether a rigid/kinematic body should have its state synchronized on the next PhysicsServer3D::flush_queries, but as of #100983 the Jolt Physics module now does the same kind of "self-listing" as Godot Physics, where each body registers with its respective physics space to have its call_queries invoked.

However, it seems I had forgot to replace one important sync_state = true with the new _enqueue_call_queries, which was the one happening in JoltBody3D::_move_kinematic, meaning we now never invoke state synchronization for things like AnimatableBody3D, which relies on this for its sync_to_physics property.

With this PR we now instead always _enqueue_call_queries if any active JoltBody3D has a valid state synchronization callback or a valid custom integration callback before stepping the simulation, which should bring it in line with Godot Physics.

(I also removed/inlined _pre_step_rigid and _pre_step_kinematic as they felt a bit excessive now.)

@rburing
Copy link
Member

rburing commented Jan 19, 2025

The reports_contacts() condition disappeared, is it ok? Just sanity checking.

@mihe
Copy link
Contributor Author

mihe commented Jan 19, 2025

The reports_contacts() condition disappeared, is it ok? Just sanity checking.

Yes! That was a remnant from the previous sync_state approach, to emulate the behavior of Godot Physics, where kinematic bodies that report contacts (i.e. a RigidBody3D frozen as kinematic) are never allowed to go to sleep and thus always have their state synchronization (and thus _integrate_forces) called.

It's not needed as of #100983, since we also prevent those types of bodies from going to sleep, meaning JoltBody3D::pre_step (and thus _enqueue_call_queries) will always be called on them.

@Repiteo Repiteo merged commit 7c69fbd into godotengine:master Jan 20, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Jan 20, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jolt Physics and sync_to_physics prevents any AnimatableBody3D transforms
3 participants