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 transform sync in RigidBody*D::_body_state_changed #84924

Merged
merged 1 commit into from
Nov 15, 2023
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
Fix transform sync in RigidBody*D::_body_state_changed
  • Loading branch information
mihe committed Nov 15, 2023
commit a3278c772eccedd035d2880cc33a11cab00fd0fc
8 changes: 6 additions & 2 deletions scene/2d/physics_body_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 12 additions & 4 deletions scene/3d/physics_body_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down