mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-23 15:50:20 +00:00
Fix camera snapping to upper floors with step-up constraint and ceiling check
Reduced camera floor step-up budget from 3.0f to 0.5f to prevent snapping to floors far above camera. Added upward raycast to detect ceilings/upper floors and constrain zoom distance in multi-story buildings, preventing camera from phasing through upper levels.
This commit is contained in:
parent
85ff6234cb
commit
b47bfdc644
1 changed files with 16 additions and 1 deletions
|
|
@ -617,6 +617,21 @@ void CameraController::update(float deltaTime) {
|
|||
if (cachedInsideWMO && currentDistance > WMO_MAX_DISTANCE) {
|
||||
currentDistance = WMO_MAX_DISTANCE;
|
||||
}
|
||||
|
||||
// Constrain zoom if there's a ceiling/upper floor above player
|
||||
// Raycast upward from player to find ceiling, limit camera distance
|
||||
glm::vec3 upRayOrigin = targetPos;
|
||||
glm::vec3 upRayDir(0.0f, 0.0f, 1.0f);
|
||||
float ceilingDist = wmoRenderer->raycast(upRayOrigin, upRayDir, 15.0f);
|
||||
if (ceilingDist < 15.0f) {
|
||||
// Found ceiling above — limit zoom to prevent camera from going through it
|
||||
// Camera is behind player by currentDistance, at an angle
|
||||
// Approximate: if ceiling is N units above, limit zoom to ~N units
|
||||
float maxZoomForCeiling = std::max(1.5f, ceilingDist * 0.7f);
|
||||
if (currentDistance > maxZoomForCeiling) {
|
||||
currentDistance = maxZoomForCeiling;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===== Camera collision (sphere sweep approximation) =====
|
||||
|
|
@ -672,7 +687,7 @@ void CameraController::update(float deltaTime) {
|
|||
}
|
||||
}
|
||||
auto camFloorH = selectReachableFloor(
|
||||
camTerrainH, camWmoH, smoothedCamPos.z, 3.0f);
|
||||
camTerrainH, camWmoH, smoothedCamPos.z, 0.5f);
|
||||
if (camFloorH && smoothedCamPos.z < *camFloorH + MIN_FLOOR_CLEARANCE) {
|
||||
smoothedCamPos.z = *camFloorH + MIN_FLOOR_CLEARANCE;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue