From b7479cbb5051f6daf70af382ee03a2cc65490f64 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 11 Mar 2026 17:02:15 -0700 Subject: [PATCH] Fix running animation hitching by using duration subtraction instead of fmod Replace floating-point fmod() with iterative duration subtraction to preserve precision. When animation time accumulates over many loops, fmod() loses precision with large values, causing subtle jumps/hitches in looping animations. Subtracting the duration instead keeps animationTime bounded in [0, duration) and avoids precision loss. --- src/rendering/character_renderer.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rendering/character_renderer.cpp b/src/rendering/character_renderer.cpp index 730a9bc3..2fcf2ef7 100644 --- a/src/rendering/character_renderer.cpp +++ b/src/rendering/character_renderer.cpp @@ -1648,7 +1648,13 @@ void CharacterRenderer::update(float deltaTime, const glm::vec3& cameraPos) { inst.animationTime += deltaTime * 1000.0f; if (seq.duration > 0 && inst.animationTime >= static_cast(seq.duration)) { if (inst.animationLoop) { - inst.animationTime = std::fmod(inst.animationTime, static_cast(seq.duration)); + // Subtract duration instead of fmod to preserve float precision + // fmod() loses precision with large animationTime values + inst.animationTime -= static_cast(seq.duration); + // Clamp to [0, duration) to handle multiple loops in one frame + while (inst.animationTime >= static_cast(seq.duration)) { + inst.animationTime -= static_cast(seq.duration); + } } else { // One-shot animation finished: return to Stand (0) unless dead if (inst.currentAnimationId != 1 /*Death*/) {