Skip to content

Commit 0804cc2

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 c526c08 commit 0804cc2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/game/game.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,15 +1276,19 @@ namespace game
12761276
}
12771277
if(crouching || d->crouching(true))
12781278
{
1279-
float zamt = zoff*curtime/float(PHYSMILLIS);
1279+
float crouchanimspeedscale = 0.35f;
1280+
12801281
if(crouching)
12811282
{
1283+
// asymptoptic smoothing of crouch view height (smoother than linear interpolation)
1284+
float zamt = abs(d->height - zrad) * crouchanimspeedscale * zoff*curtime/float(PHYSMILLIS);
12821285
if(d->actiontime[AC_CROUCH] <= 0) d->actiontime[AC_CROUCH] = lastmillis;
12831286
if(d->height > zrad && ((d->height -= zamt) < zrad)) d->height = zrad;
12841287
else if(d->height < zrad && ((d->height += zamt) > zrad)) d->height = zrad;
12851288
}
12861289
else
12871290
{
1291+
float zamt = abs(d->height - d->zradius) * crouchanimspeedscale * zoff*curtime/float(PHYSMILLIS);
12881292
if(d->actiontime[AC_CROUCH] >= 0) d->actiontime[AC_CROUCH] = -lastmillis;
12891293
if(d->height < d->zradius && ((d->height += zamt) > d->zradius)) d->height = d->zradius;
12901294
else if(d->height > d->zradius && ((d->height -= zamt) < d->zradius)) d->height = d->zradius;

0 commit comments

Comments
 (0)