From 29ab86aa7dc4aef45085d39080be757b4389f8dd Mon Sep 17 00:00:00 2001 From: Ricardo Buring Date: Tue, 6 Dec 2022 13:12:05 +0100 Subject: Fix collision detection for degenerate capsules In GodotCapsuleShape3D::get_supports and GodotCapsuleShape2D::get_supports, return a point instead of an edge of length zero in case the capsule degenerates to a sphere or circle. --- servers/physics_3d/godot_shape_3d.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'servers/physics_3d') 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; -- cgit v1.2.3