Increase wall collision sweep steps to prevent clipping

This commit is contained in:
Kelsi 2026-02-05 18:02:41 -08:00
parent f3f97cf9de
commit 8bd60c3320

View file

@ -356,10 +356,10 @@ void CameraController::update(float deltaTime) {
glm::vec3 startPos = *followTarget;
glm::vec3 desiredPos = targetPos;
float moveDist = glm::length(desiredPos - startPos);
// Adaptive CCD: keep per-step movement short, especially on low FPS spikes.
int sweepSteps = std::max(1, std::min(4, static_cast<int>(std::ceil(moveDist / 0.5f))));
// Adaptive CCD: keep per-step movement short to avoid clipping through walls.
int sweepSteps = std::max(1, std::min(8, static_cast<int>(std::ceil(moveDist / 0.3f))));
if (deltaTime > 0.04f) {
sweepSteps = std::min(6, std::max(sweepSteps, static_cast<int>(std::ceil(deltaTime / 0.016f))));
sweepSteps = std::min(12, std::max(sweepSteps, static_cast<int>(std::ceil(deltaTime / 0.016f))));
}
glm::vec3 stepPos = startPos;
glm::vec3 stepDelta = (desiredPos - startPos) / static_cast<float>(sweepSteps);
@ -782,9 +782,10 @@ void CameraController::update(float deltaTime) {
glm::vec3 startFeet = camera->getPosition() - glm::vec3(0, 0, eyeHeight);
glm::vec3 desiredFeet = newPos - glm::vec3(0, 0, eyeHeight);
float moveDist = glm::length(desiredFeet - startFeet);
int sweepSteps = std::max(1, std::min(4, static_cast<int>(std::ceil(moveDist / 0.5f))));
// Adaptive CCD: keep per-step movement short to avoid clipping through walls.
int sweepSteps = std::max(1, std::min(8, static_cast<int>(std::ceil(moveDist / 0.3f))));
if (deltaTime > 0.04f) {
sweepSteps = std::min(6, std::max(sweepSteps, static_cast<int>(std::ceil(deltaTime / 0.016f))));
sweepSteps = std::min(12, std::max(sweepSteps, static_cast<int>(std::ceil(deltaTime / 0.016f))));
}
glm::vec3 stepPos = startFeet;
glm::vec3 stepDelta = (desiredFeet - startFeet) / static_cast<float>(sweepSteps);