diff --git a/servers/physics_2d/godot_area_pair_2d.cpp b/servers/physics_2d/godot_area_pair_2d.cpp index bd1540bac86..ca12e30c292 100644 --- a/servers/physics_2d/godot_area_pair_2d.cpp +++ b/servers/physics_2d/godot_area_pair_2d.cpp @@ -66,6 +66,7 @@ bool GodotAreaPair2D::pre_solve(real_t p_step) { if (colliding) { if (has_space_override) { + body_has_attached_area = true; body->add_area(area); } @@ -74,6 +75,7 @@ bool GodotAreaPair2D::pre_solve(real_t p_step) { } } else { if (has_space_override) { + body_has_attached_area = false; body->remove_area(area); } @@ -103,7 +105,8 @@ GodotAreaPair2D::GodotAreaPair2D(GodotBody2D *p_body, int p_body_shape, GodotAre GodotAreaPair2D::~GodotAreaPair2D() { if (colliding) { - if (has_space_override) { + if (body_has_attached_area) { + body_has_attached_area = false; body->remove_area(area); } if (area->has_monitor_callback()) { diff --git a/servers/physics_2d/godot_area_pair_2d.h b/servers/physics_2d/godot_area_pair_2d.h index 938b9813b4c..eb091288a90 100644 --- a/servers/physics_2d/godot_area_pair_2d.h +++ b/servers/physics_2d/godot_area_pair_2d.h @@ -43,6 +43,7 @@ class GodotAreaPair2D : public GodotConstraint2D { bool colliding = false; bool has_space_override = false; bool process_collision = false; + bool body_has_attached_area = false; public: virtual bool setup(real_t p_step) override; diff --git a/servers/physics_3d/godot_area_pair_3d.cpp b/servers/physics_3d/godot_area_pair_3d.cpp index 5561210f2d3..aaa96f5a289 100644 --- a/servers/physics_3d/godot_area_pair_3d.cpp +++ b/servers/physics_3d/godot_area_pair_3d.cpp @@ -67,6 +67,7 @@ bool GodotAreaPair3D::pre_solve(real_t p_step) { if (colliding) { if (has_space_override) { + body_has_attached_area = true; body->add_area(area); } @@ -75,6 +76,7 @@ bool GodotAreaPair3D::pre_solve(real_t p_step) { } } else { if (has_space_override) { + body_has_attached_area = false; body->remove_area(area); } @@ -104,7 +106,8 @@ GodotAreaPair3D::GodotAreaPair3D(GodotBody3D *p_body, int p_body_shape, GodotAre GodotAreaPair3D::~GodotAreaPair3D() { if (colliding) { - if (has_space_override) { + if (body_has_attached_area) { + body_has_attached_area = false; body->remove_area(area); } if (area->has_monitor_callback()) { @@ -242,6 +245,7 @@ bool GodotAreaSoftBodyPair3D::pre_solve(real_t p_step) { if (colliding) { if (has_space_override) { + body_has_attached_area = true; soft_body->add_area(area); } @@ -250,6 +254,7 @@ bool GodotAreaSoftBodyPair3D::pre_solve(real_t p_step) { } } else { if (has_space_override) { + body_has_attached_area = false; soft_body->remove_area(area); } @@ -276,7 +281,8 @@ GodotAreaSoftBodyPair3D::GodotAreaSoftBodyPair3D(GodotSoftBody3D *p_soft_body, i GodotAreaSoftBodyPair3D::~GodotAreaSoftBodyPair3D() { if (colliding) { - if (has_space_override) { + if (body_has_attached_area) { + body_has_attached_area = false; soft_body->remove_area(area); } if (area->has_monitor_callback()) { diff --git a/servers/physics_3d/godot_area_pair_3d.h b/servers/physics_3d/godot_area_pair_3d.h index c11fa078275..a2c5df0f7ad 100644 --- a/servers/physics_3d/godot_area_pair_3d.h +++ b/servers/physics_3d/godot_area_pair_3d.h @@ -44,6 +44,7 @@ class GodotAreaPair3D : public GodotConstraint3D { bool colliding = false; bool process_collision = false; bool has_space_override = false; + bool body_has_attached_area = false; public: virtual bool setup(real_t p_step) override; @@ -83,6 +84,7 @@ class GodotAreaSoftBodyPair3D : public GodotConstraint3D { bool colliding = false; bool process_collision = false; bool has_space_override = false; + bool body_has_attached_area = false; public: virtual bool setup(real_t p_step) override;