Selaa lähdekoodia

Fix body leaving area gravity influence

(cherry picked from commit 492f1c2406fa0f8d0958bcb578d101e409a60237)
Occalepsus 1 vuosi sitten
vanhempi
commit
c12a46d3f4

+ 4 - 1
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()) {

+ 1 - 0
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;

+ 8 - 2
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()) {

+ 2 - 0
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;