summaryrefslogtreecommitdiff
path: root/servers/physics_2d
diff options
context:
space:
mode:
Diffstat (limited to 'servers/physics_2d')
-rw-r--r--servers/physics_2d/godot_body_2d.cpp13
-rw-r--r--servers/physics_2d/godot_body_2d.h5
2 files changed, 16 insertions, 2 deletions
diff --git a/servers/physics_2d/godot_body_2d.cpp b/servers/physics_2d/godot_body_2d.cpp
index b0885a1f7b..a18c748e1d 100644
--- a/servers/physics_2d/godot_body_2d.cpp
+++ b/servers/physics_2d/godot_body_2d.cpp
@@ -119,6 +119,8 @@ void GodotBody2D::update_mass_properties() {
} break;
}
+
+ _update_transform_dependent();
}
void GodotBody2D::reset_mass_properties() {
@@ -179,7 +181,8 @@ void GodotBody2D::set_param(PhysicsServer2D::BodyParameter p_param, const Varian
} break;
case PhysicsServer2D::BODY_PARAM_CENTER_OF_MASS: {
calculate_center_of_mass = false;
- center_of_mass = p_value;
+ center_of_mass_local = p_value;
+ _update_transform_dependent();
} break;
case PhysicsServer2D::BODY_PARAM_GRAVITY_SCALE: {
gravity_scale = p_value;
@@ -273,6 +276,7 @@ PhysicsServer2D::BodyMode GodotBody2D::get_mode() const {
void GodotBody2D::_shapes_changed() {
_mass_properties_changed();
+ wakeup();
wakeup_neighbours();
}
@@ -301,6 +305,7 @@ void GodotBody2D::set_state(PhysicsServer2D::BodyState p_state, const Variant &p
}
_set_transform(t);
_set_inv_transform(get_transform().inverse());
+ _update_transform_dependent();
}
wakeup();
@@ -400,6 +405,10 @@ void GodotBody2D::_compute_area_gravity_and_damping(const GodotArea2D *p_area) {
area_angular_damp += p_area->get_angular_damp();
}
+void GodotBody2D::_update_transform_dependent() {
+ center_of_mass = get_transform().basis_xform(center_of_mass_local);
+}
+
void GodotBody2D::integrate_forces(real_t p_step) {
if (mode == PhysicsServer2D::BODY_MODE_STATIC) {
return;
@@ -568,6 +577,8 @@ void GodotBody2D::integrate_velocities(real_t p_step) {
if (continuous_cd_mode != PhysicsServer2D::CCD_MODE_DISABLED) {
new_transform = get_transform();
}
+
+ _update_transform_dependent();
}
void GodotBody2D::wakeup_neighbours() {
diff --git a/servers/physics_2d/godot_body_2d.h b/servers/physics_2d/godot_body_2d.h
index c4f3578f1b..5fce362fa7 100644
--- a/servers/physics_2d/godot_body_2d.h
+++ b/servers/physics_2d/godot_body_2d.h
@@ -66,6 +66,7 @@ class GodotBody2D : public GodotCollisionObject2D {
real_t inertia = 0.0;
real_t _inv_inertia = 0.0;
+ Vector2 center_of_mass_local;
Vector2 center_of_mass;
bool calculate_inertia = true;
@@ -139,7 +140,9 @@ class GodotBody2D : public GodotCollisionObject2D {
uint64_t island_step = 0;
- _FORCE_INLINE_ void _compute_area_gravity_and_damping(const GodotArea2D *p_area);
+ void _compute_area_gravity_and_damping(const GodotArea2D *p_area);
+
+ void _update_transform_dependent();
friend class GodotPhysicsDirectBodyState2D; // i give up, too many functions to expose