diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-11-15 14:32:18 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-11-15 14:32:18 +0100 |
commit | e0707a068c6ce9fe8ad62fcfb8ccedfa7b7367a6 (patch) | |
tree | 31a134fe48123c193368fbf749735193ea3715c7 | |
parent | 00177d77353346586f760c70cf958eaedf0ced8e (diff) | |
parent | a3278c772eccedd035d2880cc33a11cab00fd0fc (diff) | |
download | redot-engine-e0707a068c6ce9fe8ad62fcfb8ccedfa7b7367a6.tar.gz |
Merge pull request #84924 from mihe/fix-84919
Fix transform sync in `RigidBody*D::_body_state_changed`
-rw-r--r-- | scene/2d/physics_body_2d.cpp | 8 | ||||
-rw-r--r-- | scene/3d/physics_body_3d.cpp | 16 |
2 files changed, 18 insertions, 6 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 45533732c7..6af5a8dd80 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -451,10 +451,14 @@ void RigidBody2D::_body_state_changed(PhysicsDirectBodyState2D *p_state) { if (GDVIRTUAL_IS_OVERRIDDEN(_integrate_forces)) { _sync_body_state(p_state); + Transform2D old_transform = get_global_transform(); GDVIRTUAL_CALL(_integrate_forces, p_state); + Transform2D new_transform = get_global_transform(); - // Update the physics server with any new transform, to prevent it from being overwritten at the sync below. - force_update_transform(); + if (new_transform != old_transform) { + // Update the physics server with the new transform, to prevent it from being overwritten at the sync below. + PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_TRANSFORM, new_transform); + } } _sync_body_state(p_state); diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index e8d05f129f..ed64c16564 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -506,10 +506,14 @@ void RigidBody3D::_body_state_changed(PhysicsDirectBodyState3D *p_state) { if (GDVIRTUAL_IS_OVERRIDDEN(_integrate_forces)) { _sync_body_state(p_state); + Transform3D old_transform = get_global_transform(); GDVIRTUAL_CALL(_integrate_forces, p_state); + Transform3D new_transform = get_global_transform(); - // Update the physics server with any new transform, to prevent it from being overwritten at the sync below. - force_update_transform(); + if (new_transform != old_transform) { + // Update the physics server with the new transform, to prevent it from being overwritten at the sync below. + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_TRANSFORM, new_transform); + } } _sync_body_state(p_state); @@ -2945,10 +2949,14 @@ void PhysicalBone3D::_body_state_changed(PhysicsDirectBodyState3D *p_state) { if (GDVIRTUAL_IS_OVERRIDDEN(_integrate_forces)) { _sync_body_state(p_state); + Transform3D old_transform = get_global_transform(); GDVIRTUAL_CALL(_integrate_forces, p_state); + Transform3D new_transform = get_global_transform(); - // Update the physics server with any new transform, to prevent it from being overwritten at the sync below. - force_update_transform(); + if (new_transform != old_transform) { + // Update the physics server with the new transform, to prevent it from being overwritten at the sync below. + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_TRANSFORM, new_transform); + } } _sync_body_state(p_state); |