From d804c34285b0a8bea9de17d8c99160815d5bbc4d Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Thu, 21 Oct 2021 17:28:27 -0700 Subject: [PATCH] Fix RigidDynamicBody 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 GodotBody3D::_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_2d/godot_body_2d.cpp | 1 + servers/physics_3d/godot_body_3d.cpp | 2 ++ servers/physics_3d/godot_physics_server_3d.cpp | 2 -- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/servers/physics_2d/godot_body_2d.cpp b/servers/physics_2d/godot_body_2d.cpp index 68f114a34a75..a18c748e1dc2 100644 --- a/servers/physics_2d/godot_body_2d.cpp +++ b/servers/physics_2d/godot_body_2d.cpp @@ -276,6 +276,7 @@ PhysicsServer2D::BodyMode GodotBody2D::get_mode() const { void GodotBody2D::_shapes_changed() { _mass_properties_changed(); + wakeup(); wakeup_neighbours(); } diff --git a/servers/physics_3d/godot_body_3d.cpp b/servers/physics_3d/godot_body_3d.cpp index 0564c4d4522a..02929eeaed6b 100644 --- a/servers/physics_3d/godot_body_3d.cpp +++ b/servers/physics_3d/godot_body_3d.cpp @@ -327,6 +327,8 @@ PhysicsServer3D::BodyMode GodotBody3D::get_mode() const { void GodotBody3D::_shapes_changed() { _mass_properties_changed(); + wakeup(); + wakeup_neighbours(); } void GodotBody3D::set_state(PhysicsServer3D::BodyState p_state, const Variant &p_variant) { diff --git a/servers/physics_3d/godot_physics_server_3d.cpp b/servers/physics_3d/godot_physics_server_3d.cpp index 34b56e733eb4..79a2e0b0eacf 100644 --- a/servers/physics_3d/godot_physics_server_3d.cpp +++ b/servers/physics_3d/godot_physics_server_3d.cpp @@ -584,7 +584,6 @@ void GodotPhysicsServer3D::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 GodotPhysicsServer3D::body_get_collision_layer(RID p_body) const { @@ -599,7 +598,6 @@ void GodotPhysicsServer3D::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 GodotPhysicsServer3D::body_get_collision_mask(RID p_body) const {