summaryrefslogtreecommitdiffstats
path: root/scene/2d/physics_body_2d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d/physics_body_2d.cpp')
-rw-r--r--scene/2d/physics_body_2d.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index baa3b0bb90..6af5a8dd80 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -431,7 +431,9 @@ struct _RigidBody2DInOut {
void RigidBody2D::_sync_body_state(PhysicsDirectBodyState2D *p_state) {
if (!freeze || freeze_mode != FREEZE_MODE_KINEMATIC) {
+ set_block_transform_notify(true);
set_global_transform(p_state->get_transform());
+ set_block_transform_notify(false);
}
linear_velocity = p_state->get_linear_velocity();
@@ -446,16 +448,20 @@ void RigidBody2D::_sync_body_state(PhysicsDirectBodyState2D *p_state) {
void RigidBody2D::_body_state_changed(PhysicsDirectBodyState2D *p_state) {
lock_callback();
- set_block_transform_notify(true); // don't want notify (would feedback loop)
-
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();
+
+ 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);
- set_block_transform_notify(false); // want it back
if (contact_monitor) {
contact_monitor->locked = true;