Skip to content

Commit

Permalink
Improve camera smoothing when crouching
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Calinou committed Dec 30, 2021
1 parent c526c08 commit 0804cc2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0804cc2

Please sign in to comment.