From 562d9cef1bc6286c2d51808a4ad5432a87de3d8d Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Thu, 21 Oct 2021 15:53:45 -0700 Subject: [PATCH] Fix RigidBody collision update after changing collision layer/mask Changing the collision layer of a sleeping body was not triggering area updates correctly. Bodies need to be active for collision to be checked against already overlapping bodies and areas. Neighbors need to be activated too in order to handle the case where a static body is modified (it can't be activated directly but paired bodies need to check their collision again). In 3D, moved the call to wakeup() from the physics server to BodySW::_shapes_changed to make it consistent with 2D and also handle the case where shapes are modified (_shapes_changed is called in both this case and collision layer changes). --- servers/physics/body_sw.cpp | 2 ++ servers/physics/physics_server_sw.cpp | 2 -- servers/physics_2d/body_2d_sw.cpp | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp index e6ecd4b66e0..eb556692d3c 100644 --- a/servers/physics/body_sw.cpp +++ b/servers/physics/body_sw.cpp @@ -287,6 +287,8 @@ PhysicsServer::BodyMode BodySW::get_mode() const { void BodySW::_shapes_changed() { _update_inertia(); + wakeup(); + wakeup_neighbours(); } void BodySW::set_state(PhysicsServer::BodyState p_state, const Variant &p_variant) { diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp index 825bca2591c..c889d918739 100644 --- a/servers/physics/physics_server_sw.cpp +++ b/servers/physics/physics_server_sw.cpp @@ -578,7 +578,6 @@ void PhysicsServerSW::body_set_collision_layer(RID p_body, uint32_t p_layer) { ERR_FAIL_COND(!body); body->set_collision_layer(p_layer); - body->wakeup(); } uint32_t PhysicsServerSW::body_get_collision_layer(RID p_body) const { @@ -593,7 +592,6 @@ void PhysicsServerSW::body_set_collision_mask(RID p_body, uint32_t p_mask) { ERR_FAIL_COND(!body); body->set_collision_mask(p_mask); - body->wakeup(); } uint32_t PhysicsServerSW::body_get_collision_mask(RID p_body) const { diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp index f6a677335a8..1e96c4191b7 100644 --- a/servers/physics_2d/body_2d_sw.cpp +++ b/servers/physics_2d/body_2d_sw.cpp @@ -251,6 +251,7 @@ Physics2DServer::BodyMode Body2DSW::get_mode() const { void Body2DSW::_shapes_changed() { _update_inertia(); + wakeup(); wakeup_neighbours(); }