From fd29aa61579141c605c5edfc3b26cdaf27e26690 Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Wed, 17 Mar 2021 18:12:40 +0100 Subject: [PATCH] strafehud: fix strafe turning with analog input --- qcsrc/client/hud/panel/strafehud.qc | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index f4cfd30de..b2eb48949 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -31,6 +31,7 @@ bool state_strafekeys = false; float state_strafekeys_time = 0; bool turn = false; float turnangle; +float turnspeed; bool fwd = true; bool state_fwd = true; bool state_fwd_prev = true; @@ -247,7 +248,7 @@ void HUD_StrafeHUD() } } - strafekeys = fabs(wishangle) == 90; + strafekeys = fabs(wishangle) > 45; // determine minimum required angle to display full strafe range range_minangle = fabs(wishangle) % 90; // maximum range is 90 degree @@ -287,7 +288,7 @@ void HUD_StrafeHUD() } state_strafekeys = strafekeys; - if((keys & KEY_FORWARD) || (keys & KEY_BACKWARD) || swimming || autocvar__hud_configure) + if((!strafekeys && vlen(vec2(movement)) > 0) || swimming || autocvar__hud_configure) { turn = false; } @@ -306,6 +307,17 @@ void HUD_StrafeHUD() { turn = true; // CPMA turning turnangle = wishangle; + + // calculate the maximum air strafe speed + if(PHYS_MAXAIRSPEED(strafeplayer) == 0){ + maxspeed = turnspeed = 0; + } + else if(PHYS_MAXAIRSTRAFESPEED(strafeplayer) == 0 || PHYS_MAXAIRSPEED(strafeplayer) <= PHYS_MAXAIRSTRAFESPEED(strafeplayer)){ + maxspeed = turnspeed = PHYS_MAXAIRSPEED(strafeplayer); + } + else{ + maxspeed = turnspeed = PHYS_MAXAIRSPEED(strafeplayer) * pow(fabs(PHYS_MAXAIRSTRAFESPEED(strafeplayer) / PHYS_MAXAIRSPEED(strafeplayer)), 1 - (90 - fabs(wishangle)) / 45); // no modifiers here because they don't affect air strafing + } } } else if((time - state_strafekeys_time) >= autocvar_hud_panel_strafehud_timeout_turn) // timeout for jumping with strafe keys only @@ -313,10 +325,10 @@ void HUD_StrafeHUD() turn = false; } } - if(turn) + if(turn && (onground || !strafekeys)) // retain last state until strafe turning times out { - maxspeed = PHYS_MAXAIRSTRAFESPEED(strafeplayer); // no modifiers here because they don't affect air strafing wishangle = turnangle; + maxspeed = turnspeed; } minspeed = autocvar_hud_panel_strafehud_switch_minspeed < 0 ? maxspeed + antiflicker_speed : autocvar_hud_panel_strafehud_switch_minspeed; @@ -335,7 +347,7 @@ void HUD_StrafeHUD() // determine whether the player is strafing forwards or backwards // if the player isn't strafe turning use forwards/backwards keys to determine direction - if(!strafekeys) + if(fabs(wishangle) != 90) { if(keys_fwd > 0) { @@ -369,7 +381,7 @@ void HUD_StrafeHUD() } state_fwd_prev = state_fwd; - if((time - state_fwd_time) >= autocvar_hud_panel_strafehud_timeout_direction || speed < maxspeed || (strafekeys && mode == 0)) // timeout when changing between forwards and backwards movement + if((time - state_fwd_time) >= autocvar_hud_panel_strafehud_timeout_direction || speed < maxspeed || ((fabs(wishangle) == 90) && mode == 0)) // timeout when changing between forwards and backwards movement { fwd = state_fwd; } -- 2.39.2