Skip to content

Commit 1a4529a

Browse files
committed
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.
1 parent 2faba36 commit 1a4529a

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/game/game.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,15 +1275,18 @@ namespace game
12751275
}
12761276
if(crouching || d->crouching(true))
12771277
{
1278-
float zamt = zoff*curtime/float(PHYSMILLIS);
12791278
if(crouching)
12801279
{
1280+
// asymptoptic smoothing of crouch view height (smoother than linear interpolation)
1281+
float zamt = abs(d->height - zrad) * 0.35f * zoff*curtime/float(PHYSMILLIS);
12811282
if(d->actiontime[AC_CROUCH] <= 0) d->actiontime[AC_CROUCH] = lastmillis;
12821283
if(d->height > zrad && ((d->height -= zamt) < zrad)) d->height = zrad;
12831284
else if(d->height < zrad && ((d->height += zamt) > zrad)) d->height = zrad;
12841285
}
12851286
else
12861287
{
1288+
// asymptoptic smoothing of crouch view height (smoother than linear interpolation)
1289+
float zamt = abs(d->height - d->zradius) * 0.35f * zoff*curtime/float(PHYSMILLIS);
12871290
if(d->actiontime[AC_CROUCH] >= 0) d->actiontime[AC_CROUCH] = -lastmillis;
12881291
if(d->height < d->zradius && ((d->height += zamt) > d->zradius)) d->height = d->zradius;
12891292
else if(d->height > d->zradius && ((d->height -= zamt) < d->zradius)) d->height = d->zradius;

0 commit comments

Comments
 (0)