summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <remi@verschelde.fr>2021-10-22 21:34:35 +0200
committerGitHub <noreply@github.com>2021-10-22 21:34:35 +0200
commitf7e6ebcdb1fd9380e015d0432c7ab1fd722fafc0 (patch)
tree93fca90f315402dba6034c69ebcee7341830fc99
parent9282b0da2751f7141fc54cbce4ef6ebbc628b6ed (diff)
parent0a04602835570804a5de4653d39b0d63de3619e8 (diff)
downloadredot-engine-f7e6ebcdb1fd9380e015d0432c7ab1fd722fafc0.tar.gz
Merge pull request #54131 from nekomatata/fix-2d-body-center-of-mass-auto
-rw-r--r--servers/physics_2d/godot_body_2d.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/servers/physics_2d/godot_body_2d.cpp b/servers/physics_2d/godot_body_2d.cpp
index a18c748e1d..c67a63a5dc 100644
--- a/servers/physics_2d/godot_body_2d.cpp
+++ b/servers/physics_2d/godot_body_2d.cpp
@@ -55,7 +55,7 @@ void GodotBody2D::update_mass_properties() {
if (calculate_center_of_mass) {
// We have to recompute the center of mass.
- center_of_mass = Vector2();
+ center_of_mass_local = Vector2();
if (total_area != 0.0) {
for (int i = 0; i < get_shape_count(); i++) {
@@ -68,10 +68,10 @@ void GodotBody2D::update_mass_properties() {
real_t mass = area * this->mass / total_area;
// NOTE: we assume that the shape origin is also its center of mass.
- center_of_mass += mass * get_shape_transform(i).get_origin();
+ center_of_mass_local += mass * get_shape_transform(i).get_origin();
}
- center_of_mass /= mass;
+ center_of_mass_local /= mass;
}
}
@@ -94,7 +94,7 @@ void GodotBody2D::update_mass_properties() {
Transform2D mtx = get_shape_transform(i);
Vector2 scale = mtx.get_scale();
- Vector2 shape_origin = mtx.get_origin() - center_of_mass;
+ Vector2 shape_origin = mtx.get_origin() - center_of_mass_local;
inertia += shape->get_moment_of_inertia(mass, scale) + mass * shape_origin.length_squared();
}
}