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).