diff options
author | Ricardo Buring <ricardo.buring@gmail.com> | 2022-12-06 13:12:05 +0100 |
---|---|---|
committer | Ricardo Buring <ricardo.buring@gmail.com> | 2022-12-06 14:17:24 +0100 |
commit | 29ab86aa7dc4aef45085d39080be757b4389f8dd (patch) | |
tree | 6b7061cd8dfbd1dc0aa2755850007b51365bf7fb /servers/physics_2d | |
parent | a8a88194a5cf5849d421aaec05beddbc437ebbcd (diff) |
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.
Diffstat (limited to 'servers/physics_2d')
-rw-r--r-- | servers/physics_2d/godot_shape_2d.cpp | 10 |
1 files changed, 4 insertions, 6 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; |