From 0804cc2772a36eddd6de2a080b394bbe0a033437 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Tue, 28 Dec 2021 23:39:08 +0100 Subject: [PATCH] Improve camera smoothing when crouching Asymptoptic (ease-out) smoothing is now used instead of linear interpolation. This kind of smoothing is often used for camera crouching animations in modern FPS games. --- src/game/game.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index cc9c06922..59d23f2c0 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -1276,15 +1276,19 @@ namespace game } if(crouching || d->crouching(true)) { - float zamt = zoff*curtime/float(PHYSMILLIS); + float crouchanimspeedscale = 0.35f; + if(crouching) { + // asymptoptic smoothing of crouch view height (smoother than linear interpolation) + float zamt = abs(d->height - zrad) * crouchanimspeedscale * zoff*curtime/float(PHYSMILLIS); if(d->actiontime[AC_CROUCH] <= 0) d->actiontime[AC_CROUCH] = lastmillis; if(d->height > zrad && ((d->height -= zamt) < zrad)) d->height = zrad; else if(d->height < zrad && ((d->height += zamt) > zrad)) d->height = zrad; } else { + float zamt = abs(d->height - d->zradius) * crouchanimspeedscale * zoff*curtime/float(PHYSMILLIS); if(d->actiontime[AC_CROUCH] >= 0) d->actiontime[AC_CROUCH] = -lastmillis; if(d->height < d->zradius && ((d->height += zamt) > d->zradius)) d->height = d->zradius; else if(d->height > d->zradius && ((d->height -= zamt) < d->zradius)) d->height = d->zradius;