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 28, 2021
1 parent 2faba36 commit 1a4529a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,15 +1275,18 @@ namespace game
}
if(crouching || d->crouching(true))
{
float zamt = zoff*curtime/float(PHYSMILLIS);
if(crouching)
{
// asymptoptic smoothing of crouch view height (smoother than linear interpolation)
float zamt = abs(d->height - zrad) * 0.35f * 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
{
// asymptoptic smoothing of crouch view height (smoother than linear interpolation)
float zamt = abs(d->height - d->zradius) * 0.35f * 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 1a4529a

Please sign in to comment.