From 6c7d52164a054719e6e26eaef67558d827aed459 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Thu, 17 Jun 2021 17:17:05 -0700 Subject: [PATCH] Ignore disabled shapes for mass property calculations (cherry picked from commit c3107349a493be16ad0de2a29a6e29f03eebbb8b) --- servers/physics/body_sw.cpp | 7 +++++++ servers/physics_2d/body_2d_sw.cpp | 3 +++ 2 files changed, 10 insertions(+) diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp index bd2523a3ae8..818b90899f0 100644 --- a/servers/physics/body_sw.cpp +++ b/servers/physics/body_sw.cpp @@ -63,6 +63,9 @@ void BodySW::update_inertias() { real_t total_area = 0; for (int i = 0; i < get_shape_count(); i++) { + if (is_shape_disabled(i)) { + continue; + } total_area += get_shape_area(i); } @@ -72,6 +75,10 @@ void BodySW::update_inertias() { if (total_area != 0.0) { for (int i = 0; i < get_shape_count(); i++) { + if (is_shape_disabled(i)) { + continue; + } + real_t area = get_shape_area(i); real_t mass = area * this->mass / total_area; diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp index b4f837b3557..9673e893f46 100644 --- a/servers/physics_2d/body_2d_sw.cpp +++ b/servers/physics_2d/body_2d_sw.cpp @@ -55,6 +55,9 @@ void Body2DSW::update_inertias() { real_t total_area = 0; for (int i = 0; i < get_shape_count(); i++) { + if (is_shape_disabled(i)) { + continue; + } total_area += get_shape_aabb(i).get_area(); }