From bf6a5ba596eb51f27556c4049376b2bd3f9ca3fc Mon Sep 17 00:00:00 2001 From: Kelsi Date: Thu, 5 Feb 2026 17:46:30 -0800 Subject: [PATCH] Improve floor detection for multi-story buildings - Increase footprint sampling radius from 0.28 to 0.4 units - Only update floor cache if found floor is close to query height - Prevents caching wrong floor from different stories --- src/rendering/camera_controller.cpp | 6 +++--- src/rendering/wmo_renderer.cpp | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/rendering/camera_controller.cpp b/src/rendering/camera_controller.cpp index 3d3799b4..d6576d77 100644 --- a/src/rendering/camera_controller.cpp +++ b/src/rendering/camera_controller.cpp @@ -518,9 +518,9 @@ void CameraController::update(float deltaTime) { return base; }; - // Sample center + small footprint to avoid slipping through narrow floor pieces. + // Sample center + footprint to avoid slipping through narrow floor pieces. std::optional groundH; - constexpr float FOOTPRINT = 0.28f; + constexpr float FOOTPRINT = 0.4f; // Larger footprint for better floor detection const glm::vec2 offsets[] = { {0.0f, 0.0f}, {FOOTPRINT, 0.0f}, {-FOOTPRINT, 0.0f}, @@ -824,7 +824,7 @@ void CameraController::update(float deltaTime) { }; std::optional groundH; - constexpr float FOOTPRINT = 0.28f; + constexpr float FOOTPRINT = 0.4f; // Larger footprint for better floor detection const glm::vec2 offsets[] = { {0.0f, 0.0f}, {FOOTPRINT, 0.0f}, {-FOOTPRINT, 0.0f}, {0.0f, FOOTPRINT}, {0.0f, -FOOTPRINT} }; diff --git a/src/rendering/wmo_renderer.cpp b/src/rendering/wmo_renderer.cpp index 4b8bd849..4087e0bb 100644 --- a/src/rendering/wmo_renderer.cpp +++ b/src/rendering/wmo_renderer.cpp @@ -1495,8 +1495,10 @@ std::optional WMORenderer::getFloorHeight(float glX, float glY, float glZ } } - // Cache the result in persistent grid (never expires) - if (bestFloor) { + // Cache the result in persistent grid. + // Only update cache if we found a floor that's close to query height, + // to avoid caching wrong floors when player is on different stories. + if (bestFloor && *bestFloor >= glZ - 6.0f) { precomputedFloorGrid[gridKey] = *bestFloor; }