From 66e2f3a8e919b934935fd941f089ffc3f2747e65 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 3 Jan 2023 02:27:03 -0800 Subject: [PATCH] Reduce stair janking loss of control if momentum angle drifts too far from facing --- src/p_user.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/p_user.c b/src/p_user.c index be70fd0e0..34c016d18 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1792,6 +1792,38 @@ static void P_DoBubbleBreath(player_t *player) } } +static inline boolean P_IsMomentumAngleLocked(player_t *player) +{ + // This timer is used for the animation too and the + // animation should continue for a bit after the physics + // stop. + + if (player->stairjank > 8) + { + const angle_t th = K_MomentumAngle(player->mo); + const angle_t d = AngleDelta(th, player->mo->angle); + + // A larger difference between momentum and facing + // angles awards back control. + // <45 deg: 3/4 tics + // >45 deg: 2/4 tics + // >90 deg: 1/4 tics + // >135 deg: 0/4 tics + + if ((leveltime & 3) > (d / ANGLE_45)) + { + return true; + } + } + + if (K_IsRidingFloatingTop(player)) + { + return true; + } + + return false; +} + //#define OLD_MOVEMENT_CODE 1 static void P_3dMovement(player_t *player) { @@ -1812,7 +1844,7 @@ static void P_3dMovement(player_t *player) // Get the old momentum; this will be needed at the end of the function! -SH oldMagnitude = R_PointToDist2(player->mo->momx - player->cmomx, player->mo->momy - player->cmomy, 0, 0); - if ((player->stairjank > 8 && leveltime & 3) || K_IsRidingFloatingTop(player)) + if (P_IsMomentumAngleLocked(player)) { movepushangle = K_MomentumAngle(player->mo); }