diff --git a/SHADE_Engine/src/Math/Geometry/SHAABB.cpp b/SHADE_Engine/src/Math/Geometry/SHAABB.cpp index f5d9fd60..99e0aebe 100644 --- a/SHADE_Engine/src/Math/Geometry/SHAABB.cpp +++ b/SHADE_Engine/src/Math/Geometry/SHAABB.cpp @@ -155,6 +155,11 @@ namespace SHADE SHRaycastResult result; result.hit = Intersects(ray.position, ray.direction, result.distance); + + // Negative distances are invalid, therefore false + if (result.distance < 0.0f) + result.hit = false; + if (result.hit) { result.position = ray.position + ray.direction * result.distance; diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp index 508f8807..d996c470 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp @@ -197,7 +197,9 @@ namespace SHADE // Load start and end points into the container for debug drawing #ifdef SHEDITOR - SHVec3 endPos = info.ray.position + info.ray.direction * SHRay::MAX_RAYCAST_DIST; + // Default end pos is how far the ray was casted. + const float DISTANCE = info.distance == std::numeric_limits::infinity() ? SHRay::MAX_RAYCAST_DIST : info.distance; + SHVec3 endPos = info.ray.position + info.ray.direction * DISTANCE; if (!results.empty()) endPos = results.back().position;