Fix joystick movement threshold and run behavior

Fixes issue where holding the movement joystick at a 45 degree angle would
instead make you move at a 41 degree angle if you had "Always Run" set to
"Vanilla" or at a 60 degree angle.

Fixes issue where holding the movement joystick all the way while not running
would make you move at speed 283 instead of 200.

Fixes issue where while running you reach the maximum speed while holding the
joystick at only 83% (when joy_exponent_move is at its default value of 3, and
when joy_exponent_move is 2, 75%, and when joy_exponent_move is 1, 57%).
This commit is contained in:
Chris Cowan 2023-03-05 04:53:13 -08:00 committed by Ozkan Sezer
parent 4a18467d36
commit 68b9ca8906
1 changed files with 14 additions and 31 deletions

View File

@ -475,29 +475,6 @@ static joyaxis_t IN_ApplyEasing(joyaxis_t axis, float exponent)
return result;
}
/*
================
IN_ApplyMoveEasing
same as IN_ApplyEasing, but scales the output by sqrt(2).
this gives diagonal stick inputs coordinates of (+/-1,+/-1).
forward/back/left/right will return +/- 1.41; this shouldn't be a problem because
you can pull back on the stick to go slower (and the final speed is clamped
by sv_maxspeed).
================
*/
static joyaxis_t IN_ApplyMoveEasing(joyaxis_t axis, float exponent)
{
joyaxis_t result = IN_ApplyEasing(axis, exponent);
const float v = sqrtf(2.0f);
result.x *= v;
result.y *= v;
return result;
}
/*
================
IN_ApplyDeadzone
@ -668,6 +645,7 @@ void IN_JoyMove (usercmd_t *cmd)
float speed;
joyaxis_t moveRaw, moveDeadzone, moveEased;
joyaxis_t lookRaw, lookDeadzone, lookEased;
extern cvar_t sv_maxspeed;
if (!joy_enable.value)
return;
@ -693,16 +671,21 @@ void IN_JoyMove (usercmd_t *cmd)
moveDeadzone = IN_ApplyDeadzone(moveRaw, joy_deadzone_move.value, joy_outer_threshold_move.value);
lookDeadzone = IN_ApplyDeadzone(lookRaw, joy_deadzone_look.value, joy_outer_threshold_look.value);
moveEased = IN_ApplyMoveEasing(moveDeadzone, joy_exponent_move.value);
moveEased = IN_ApplyEasing(moveDeadzone, joy_exponent_move.value);
lookEased = IN_ApplyEasing(lookDeadzone, joy_exponent.value);
if ((in_speed.state & 1) ^ (cl_alwaysrun.value != 0.0))
speed = cl_movespeedkey.value;
else
speed = 1;
cmd->sidemove += (cl_sidespeed.value * speed * moveEased.x);
cmd->forwardmove -= (cl_forwardspeed.value * speed * moveEased.y);
if ((in_speed.state & 1) ^ (cl_alwaysrun.value != 0.0 || cl_forwardspeed.value >= sv_maxspeed.value))
// running
speed = sv_maxspeed.value;
else if (cl_forwardspeed.value >= sv_maxspeed.value)
// not running, with always run = vanilla
speed = q_min(sv_maxspeed.value, cl_forwardspeed.value / cl_movespeedkey.value);
else
// not running, with always run = off or quakespasm
speed = cl_forwardspeed.value;
cmd->sidemove += speed * moveEased.x;
cmd->forwardmove -= speed * moveEased.y;
cl.viewangles[YAW] -= lookEased.x * joy_sensitivity_yaw.value * host_frametime;
cl.viewangles[PITCH] += lookEased.y * joy_sensitivity_pitch.value * (joy_invert.value ? -1.0 : 1.0) * host_frametime;