From e768f5048c1dcec10e8d58b4a3d929f93d95bf19 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Thu, 5 Feb 2026 17:41:46 -0800 Subject: [PATCH] Fix floor cache for multi-story buildings Skip cached floor height if it's too far below query point (>4 units), forcing a full raycast. This handles cases where the cache has a different floor's height (e.g., ground floor cached while on upper floor). --- src/rendering/wmo_renderer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rendering/wmo_renderer.cpp b/src/rendering/wmo_renderer.cpp index 376f0ca1..4b8bd849 100644 --- a/src/rendering/wmo_renderer.cpp +++ b/src/rendering/wmo_renderer.cpp @@ -1392,8 +1392,10 @@ std::optional WMORenderer::getFloorHeight(float glX, float glY, float glZ auto gridIt = precomputedFloorGrid.find(gridKey); if (gridIt != precomputedFloorGrid.end()) { float cachedHeight = gridIt->second; - // Only use if cached height is below query point (not a ceiling) - if (cachedHeight <= glZ + 2.0f) { + // Only use cache if floor is close to query point (within ~4 units below). + // For multi-story buildings, the cache has the top floor - if we're on a + // lower floor, skip cache and do full raycast to find actual floor. + if (cachedHeight <= glZ + 2.0f && cachedHeight >= glZ - 4.0f) { return cachedHeight; } }