mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-25 16:30:15 +00:00
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.
This commit is contained in:
parent
eb3cdbcc5f
commit
b7479cbb50
1 changed files with 7 additions and 1 deletions
|
|
@ -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<float>(seq.duration)) {
|
||||
if (inst.animationLoop) {
|
||||
inst.animationTime = std::fmod(inst.animationTime, static_cast<float>(seq.duration));
|
||||
// Subtract duration instead of fmod to preserve float precision
|
||||
// fmod() loses precision with large animationTime values
|
||||
inst.animationTime -= static_cast<float>(seq.duration);
|
||||
// Clamp to [0, duration) to handle multiple loops in one frame
|
||||
while (inst.animationTime >= static_cast<float>(seq.duration)) {
|
||||
inst.animationTime -= static_cast<float>(seq.duration);
|
||||
}
|
||||
} else {
|
||||
// One-shot animation finished: return to Stand (0) unless dead
|
||||
if (inst.currentAnimationId != 1 /*Death*/) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue