Skip to content

Commit

Permalink
Fix kinematic bodies not synchronizing state when using Jolt Physics
Browse files Browse the repository at this point in the history
  • Loading branch information
mihe committed Jan 19, 2025
1 parent 7b1ed52 commit f4288fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
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

0 comments on commit f4288fb

Please sign in to comment.