From c5ecba0327a22348333e8b377bb6d9bb827c0a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Leone=20G=C3=A1mez?= Date: Sat, 2 Mar 2019 18:49:32 +0100 Subject: [PATCH] Fix Raycast reporting false positives for rays that cross a bounding box but not the shape that is inside it, thanks to analyzing BEPU Physics raycasting source code https://github.com/bepu/bepuphysics1/blob/e0438719412e2eab8683d5ca65c1b0bb0e9b177a/BEPUphysics/CollisionTests/CollisionAlgorithms/GJK/GJKToolbox.cs#L347 --- source/Jitter/Collision/GJKCollide.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/Jitter/Collision/GJKCollide.cs b/source/Jitter/Collision/GJKCollide.cs index 044842d6..23b1c9f6 100644 --- a/source/Jitter/Collision/GJKCollide.cs +++ b/source/Jitter/Collision/GJKCollide.cs @@ -346,6 +346,12 @@ public static bool Raycast(ISupportMappable support, ref JMatrix orientation, re else { lambda = lambda - VdotW / VdotR; + if (lambda > 1) + { + //If we've gone beyond where the ray can reach, there's obviously no hit. + simplexSolverPool.GiveBack(simplexSolver); + return false; + } JVector.Multiply(ref r, lambda, out x); JVector.Add(ref origin, ref x, out x); JVector.Subtract(ref x, ref p, out w);