From f4b086c5245d40e370ba8ed73e96f982aa007062 Mon Sep 17 00:00:00 2001 From: Ross Nordby Date: Sat, 16 Nov 2024 13:35:45 -0600 Subject: [PATCH] Fixed a special case hole that allowed negative values to be reported for hits on cylinders. --- BepuPhysics/Collidables/Cylinder.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BepuPhysics/Collidables/Cylinder.cs b/BepuPhysics/Collidables/Cylinder.cs index 8041c2d4..0eadc9c0 100644 --- a/BepuPhysics/Collidables/Cylinder.cs +++ b/BepuPhysics/Collidables/Cylinder.cs @@ -136,7 +136,8 @@ public readonly bool RayTest(in RigidPose pose, Vector3 origin, Vector3 directio else { //The ray is parallel to the axis; the impact is on a disc or nothing. - discY = d.Y > 0 ? -HalfLength : HalfLength; + //If the ray is inside the cylinder, we want t = 0, so just set the discY to match the ray's origin in that case and it'll shake out like we want. + discY = float.MinMagnitude(d.Y > 0 ? -HalfLength : HalfLength, o.Y); } //Intersect the ray with the plane anchored at discY with normal equal to (0,1,0).