From 7e7e56f0c6b2f1ec15f7bd5f3dd2aea0ba276b47 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Fri, 31 Jul 2020 15:46:44 -0400 Subject: [PATCH] Add distance easing, so it doesn't jitter around too much when you're stuck. --- src/p_user.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index 8d6014926..16c54c2e1 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -7714,17 +7714,40 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall } // sets ideal cam pos - dist = camdist; + { + const fixed_t speedthreshold = 48*mapobjectscale; + const fixed_t olddist = P_AproxDistance(mo->x - thiscam->x, mo->y - thiscam->y); - /* player->speed subtracts conveyors, janks up the camera */ - speed = R_PointToDist2(0, 0, player->mo->momx, player->mo->momy); + fixed_t lag, distoffset; - if (speed > K_GetKartSpeed(player, false)) - dist += 4*(speed - K_GetKartSpeed(player, false)); - dist += abs(thiscam->momz)/4; + dist = camdist; - if (player->karthud[khud_boostcam]) - dist -= FixedMul(11*dist/16, player->karthud[khud_boostcam]); + if (player->karthud[khud_boostcam]) + { + dist -= FixedMul(11*dist/16, player->karthud[khud_boostcam]); + } + + speed = P_AproxDistance(P_AproxDistance(mo->momx, mo->momy), mo->momz / 16); + lag = FRACUNIT - ((FixedDiv(speed, speedthreshold) - FRACUNIT) * 2); + + if (lag > FRACUNIT) + { + lag = FRACUNIT; + } + + if (lag < camspeed) + { + lag = camspeed; + } + + distoffset = dist - olddist; + dist = olddist + FixedMul(distoffset, lag); + + if (dist < 0) + { + dist = 0; + } + } if (mo->standingslope) { @@ -8019,7 +8042,9 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall thiscam->momz = 0; } else if (player->exiting || timeover == 2) + { thiscam->momx = thiscam->momy = thiscam->momz = 0; + } else if (leveltime < introtime) { thiscam->momx = FixedMul(x - thiscam->x, camspeed);