From 7b365956413ddc47c43b647dfc4ce4e9ec48f14f Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Fri, 17 Jun 2016 16:45:10 -0300 Subject: [PATCH] Send body inout notifications after state is applied, fixes #4683 (cherry picked from commit 95dc15b75096b7f4017b16ddae9066ee2deb3934) --- scene/2d/physics_body_2d.cpp | 26 ++++++++++++++------------ scene/3d/physics_body.cpp | 24 +++++++++++++----------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index dc038f010c8..59feaf0901e 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -450,6 +450,19 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { state=(Physics2DDirectBodyState*)p_state; //trust it #endif + set_block_transform_notify(true); // don't want notify (would feedback loop) + if (mode!=MODE_KINEMATIC) + set_global_transform(state->get_transform()); + linear_velocity=state->get_linear_velocity(); + angular_velocity=state->get_angular_velocity(); + if(sleeping!=state->is_sleeping()) { + sleeping=state->is_sleeping(); + emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed); + } + if (get_script_instance()) + get_script_instance()->call("_integrate_forces",state); + set_block_transform_notify(false); // want it back + if (contact_monitor) { contact_monitor->locked=true; @@ -539,18 +552,7 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { } - set_block_transform_notify(true); // don't want notify (would feedback loop) - if (mode!=MODE_KINEMATIC) - set_global_transform(state->get_transform()); - linear_velocity=state->get_linear_velocity(); - angular_velocity=state->get_angular_velocity(); - if(sleeping!=state->is_sleeping()) { - sleeping=state->is_sleeping(); - emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed); - } - if (get_script_instance()) - get_script_instance()->call("_integrate_forces",state); - set_block_transform_notify(false); // want it back + state=NULL; } diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index bc637eed44f..4f3b058c20d 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -328,6 +328,18 @@ void RigidBody::_direct_state_changed(Object *p_state) { state=(PhysicsDirectBodyState*)p_state; //trust it #endif + set_ignore_transform_notification(true); + set_global_transform(state->get_transform()); + linear_velocity=state->get_linear_velocity(); + angular_velocity=state->get_angular_velocity(); + if(sleeping!=state->is_sleeping()) { + sleeping=state->is_sleeping(); + emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed); + } + if (get_script_instance()) + get_script_instance()->call("_integrate_forces",state); + set_ignore_transform_notification(false); + if (contact_monitor) { contact_monitor->locked=true; @@ -415,17 +427,7 @@ void RigidBody::_direct_state_changed(Object *p_state) { } - set_ignore_transform_notification(true); - set_global_transform(state->get_transform()); - linear_velocity=state->get_linear_velocity(); - angular_velocity=state->get_angular_velocity(); - if(sleeping!=state->is_sleeping()) { - sleeping=state->is_sleeping(); - emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed); - } - if (get_script_instance()) - get_script_instance()->call("_integrate_forces",state); - set_ignore_transform_notification(false); + state=NULL; }