diff --git a/TR5Main/Game/collide.cpp b/TR5Main/Game/collide.cpp index 4e23cde52..2b2e4e128 100644 --- a/TR5Main/Game/collide.cpp +++ b/TR5Main/Game/collide.cpp @@ -2852,7 +2852,7 @@ short GetNearestLedgeAngle(ITEM_INFO* item, COLL_INFO* coll, float& dist) // Get block edge planes + split angle plane Plane plane[5] = { - Plane(Vector3(fX, cY, cZ), Vector3(cX, cY, cZ), Vector3(cX, fY, fZ)), // North + Plane(Vector3(fX, cY, cZ), Vector3(cX, cY, cZ), Vector3(cX, fY, cZ)), // North Plane(Vector3(fX, cY, fZ), Vector3(fX, cY, cZ), Vector3(fX, fY, cZ)), // West Plane(Vector3(cX, fY, fZ), Vector3(cX, cY, fZ), Vector3(fX, cY, fZ)), // South Plane(Vector3(cX, fY, cZ), Vector3(cX, cY, cZ), Vector3(cX, cY, fZ)), // East @@ -2909,22 +2909,26 @@ short GetNearestLedgeAngle(ITEM_INFO* item, COLL_INFO* coll, float& dist) // Find existing angle in results int firstEqualAngle; for (firstEqualAngle = 0; firstEqualAngle < 3; firstEqualAngle++) + { if (result[firstEqualAngle] == result[p]) break; + else if (firstEqualAngle == 2) + firstEqualAngle = 0; // No equal angles, use center one + } // Remember distance to the closest plane with same angle (it happens sometimes with bridges) float dist1 = FLT_MAX; float dist2 = FLT_MAX; auto r1 = originRay.Intersects(closestPlane[p], dist1); auto r2 = originRay.Intersects(closestPlane[firstEqualAngle], dist2); - finalDistance[h] = (dist1 > dist2 && r2) ? dist2 : (r1 ? dist1 : dist2); + finalDistance[h] = (dist1 > dist2 && r2) ? dist2 : (r1 ? dist1 : dist2); finalResult[h] = result[p]; break; } } - // Store first result in case all 3 results are different (no priority) or long-distance misfire occured + // Store first result in case all 3 results are different (no priority) or prioritized result if long-distance misfire occured if (finalDistance[h] == FLT_MAX || finalDistance[h] > WALL_SIZE / 2) { finalDistance[h] = closestDistance[0];