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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions modules/jolt_physics/objects/jolt_body_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,6 @@ void JoltBody3D::_move_kinematic(float p_step, JPH::Body &p_jolt_body) {
p_jolt_body.MoveKinematic(new_position, new_rotation, p_step);
}

void JoltBody3D::_pre_step_rigid(float p_step, JPH::Body &p_jolt_body) {
_integrate_forces(p_step, p_jolt_body);
_enqueue_call_queries();
}

void JoltBody3D::_pre_step_kinematic(float p_step, JPH::Body &p_jolt_body) {
_update_gravity(p_jolt_body);
_move_kinematic(p_step, p_jolt_body);

if (reports_contacts()) {
_enqueue_call_queries();
}
}

JPH::EAllowedDOFs JoltBody3D::_calculate_allowed_dofs() const {
if (is_static()) {
return JPH::EAllowedDOFs::All;
Expand Down Expand Up @@ -1237,13 +1223,18 @@ void JoltBody3D::pre_step(float p_step, JPH::Body &p_jolt_body) {
} break;
case PhysicsServer3D::BODY_MODE_RIGID:
case PhysicsServer3D::BODY_MODE_RIGID_LINEAR: {
_pre_step_rigid(p_step, p_jolt_body);
_integrate_forces(p_step, p_jolt_body);
} break;
case PhysicsServer3D::BODY_MODE_KINEMATIC: {
_pre_step_kinematic(p_step, p_jolt_body);
_update_gravity(p_jolt_body);
_move_kinematic(p_step, p_jolt_body);
} break;
}

if (_should_call_queries()) {
_enqueue_call_queries();
}

contact_count = 0;
}

Expand Down
4 changes: 1 addition & 3 deletions modules/jolt_physics/objects/jolt_body_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,14 @@ class JoltBody3D final : public JoltShapedObject3D {

virtual void _add_to_space() override;

bool _should_call_queries() const { return state_sync_callback.is_valid() || custom_integration_callback.is_valid(); }
void _enqueue_call_queries();
void _dequeue_call_queries();

void _integrate_forces(float p_step, JPH::Body &p_jolt_body);

void _move_kinematic(float p_step, JPH::Body &p_jolt_body);

void _pre_step_rigid(float p_step, JPH::Body &p_jolt_body);
void _pre_step_kinematic(float p_step, JPH::Body &p_jolt_body);

JPH::EAllowedDOFs _calculate_allowed_dofs() const;

JPH::MassProperties _calculate_mass_properties(const JPH::Shape &p_shape) const;
Expand Down