summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-12-06 15:16:44 +0100
committerRémi Verschelde <rverschelde@gmail.com>2022-12-06 15:16:44 +0100
commitc83695c0b5196504c6cc7acf0a99f5edbbd24d4b (patch)
tree5054cb2851f8777f32cc558015ea24e52a2ba3af /servers
parentf9aea4d94094a321d5e64763f158a4861df37cec (diff)
parent29ab86aa7dc4aef45085d39080be757b4389f8dd (diff)
Merge pull request #69657 from rburing/degenerate_capsule_has_no_edge
Fix collision detection for degenerate capsules
Diffstat (limited to 'servers')
-rw-r--r--servers/physics_2d/godot_shape_2d.cpp10
-rw-r--r--servers/physics_3d/godot_shape_3d.cpp10
2 files changed, 8 insertions, 12 deletions
diff --git a/servers/physics_2d/godot_shape_2d.cpp b/servers/physics_2d/godot_shape_2d.cpp
index da414ae233..6823cb32c1 100644
--- a/servers/physics_2d/godot_shape_2d.cpp
+++ b/servers/physics_2d/godot_shape_2d.cpp
@@ -369,8 +369,9 @@ void GodotCapsuleShape2D::get_supports(const Vector2 &p_normal, Vector2 *r_suppo
Vector2 n = p_normal;
real_t d = n.y;
+ real_t h = height * 0.5 - radius; // half-height of the rectangle part
- if (Math::abs(d) < (1.0 - _SEGMENT_IS_VALID_SUPPORT_THRESHOLD)) {
+ if (h > 0 && Math::abs(d) < (1.0 - _SEGMENT_IS_VALID_SUPPORT_THRESHOLD)) {
// make it flat
n.y = 0.0;
n.normalize();
@@ -378,13 +379,10 @@ void GodotCapsuleShape2D::get_supports(const Vector2 &p_normal, Vector2 *r_suppo
r_amount = 2;
r_supports[0] = n;
- r_supports[0].y += height * 0.5 - radius;
+ r_supports[0].y += h;
r_supports[1] = n;
- r_supports[1].y -= height * 0.5 - radius;
-
+ r_supports[1].y -= h;
} else {
- real_t h = height * 0.5 - radius;
-
n *= radius;
n.y += (d > 0) ? h : -h;
r_amount = 1;
diff --git a/servers/physics_3d/godot_shape_3d.cpp b/servers/physics_3d/godot_shape_3d.cpp
index 1443cd166b..22553bd3d8 100644
--- a/servers/physics_3d/godot_shape_3d.cpp
+++ b/servers/physics_3d/godot_shape_3d.cpp
@@ -521,8 +521,9 @@ void GodotCapsuleShape3D::get_supports(const Vector3 &p_normal, int p_max, Vecto
Vector3 n = p_normal;
real_t d = n.y;
+ real_t h = height * 0.5 - radius; // half-height of the cylinder part
- if (Math::abs(d) < edge_support_threshold) {
+ if (h > 0 && Math::abs(d) < edge_support_threshold) {
// make it flat
n.y = 0.0;
n.normalize();
@@ -531,13 +532,10 @@ void GodotCapsuleShape3D::get_supports(const Vector3 &p_normal, int p_max, Vecto
r_amount = 2;
r_type = FEATURE_EDGE;
r_supports[0] = n;
- r_supports[0].y += height * 0.5 - radius;
+ r_supports[0].y += h;
r_supports[1] = n;
- r_supports[1].y -= height * 0.5 - radius;
-
+ r_supports[1].y -= h;
} else {
- real_t h = height * 0.5 - radius;
-
n *= radius;
n.y += (d > 0) ? h : -h;
r_amount = 1;