Faster Bhop
This commit is contained in:
parent
b29f71e597
commit
deccfca8e3
|
@ -24,6 +24,8 @@ static void autostrafe_legit(usercmd_t* cmd) {
|
|||
* https://github.com/deboogerxyz/ahc/blob/0492646e28dd7234a8cd431d37b152dc18a21b04/ahc.c#L201
|
||||
* https://github.com/NullHooks/NullHooks/blob/535351569ca599cadd21a286d88098b6dc057a46/src/core/features/movement/bhop.cpp#L73
|
||||
*/
|
||||
static const float DEG2RAD_CACHED = M_PI / 180.0f;
|
||||
|
||||
static void autostrafe_rage(usercmd_t* cmd) {
|
||||
if (i_pmove->movetype != MOVETYPE_WALK)
|
||||
return;
|
||||
|
@ -48,20 +50,18 @@ static void autostrafe_rage(usercmd_t* cmd) {
|
|||
|
||||
float best_delta = acosf(term);
|
||||
|
||||
/* Use engine viewangles in case we do something nasty with cmd's angles */
|
||||
vec3_t viewangles;
|
||||
i_engine->GetViewAngles(viewangles);
|
||||
|
||||
/* Get our desired angles and delta */
|
||||
float yaw = DEG2RAD(viewangles.y);
|
||||
float vel_dir = atan2f(i_pmove->velocity.y, i_pmove->velocity.x) - yaw;
|
||||
float yaw = viewangles.y * DEG2RAD_CACHED;
|
||||
float vel_dir = atan2f(i_pmove->velocity.y, i_pmove->velocity.x) - yaw;
|
||||
float target_ang = atan2f(-cmd->sidemove, cmd->forwardmove);
|
||||
float delta = angle_delta_rad(vel_dir, target_ang);
|
||||
float delta = angle_delta_rad(vel_dir, target_ang);
|
||||
|
||||
float movedir = delta < 0 ? vel_dir + best_delta : vel_dir - best_delta;
|
||||
|
||||
cmd->forwardmove = cosf(movedir) * cl_forwardspeed;
|
||||
cmd->sidemove = -sinf(movedir) * cl_sidespeed;
|
||||
cmd->sidemove = -sinf(movedir) * cl_sidespeed;
|
||||
}
|
||||
|
||||
void bhop(usercmd_t* cmd) {
|
||||
|
@ -101,18 +101,15 @@ void bhop(usercmd_t* cmd) {
|
|||
* https://github.com/deboogerxyz/ahc/blob/0492646e28dd7234a8cd431d37b152dc18a21b04/ahc.c#L377
|
||||
*/
|
||||
void correct_movement(usercmd_t* cmd, vec3_t old_angles) {
|
||||
float old_y = old_angles.y + (old_angles.y < 0 ? 360 : 0);
|
||||
float new_y = cmd->viewangles.y + (cmd->viewangles.y < 0 ? 360 : 0);
|
||||
float delta = (new_y < old_y) ? fabsf(new_y - old_y)
|
||||
: 360 - fabsf(new_y - old_y);
|
||||
|
||||
delta = 360 - delta;
|
||||
float delta_y = fmodf(cmd->viewangles.y - old_angles.y + 540.0f, 360.0f) - 180.0f; // Normalized delta in [-180, 180)
|
||||
|
||||
float delta_rad = delta_y * DEG2RAD_CACHED;
|
||||
float delta_cos = cosf(delta_rad);
|
||||
float delta_sin = sinf(delta_rad);
|
||||
|
||||
float forward = cmd->forwardmove;
|
||||
float side = cmd->sidemove;
|
||||
float side = cmd->sidemove;
|
||||
|
||||
cmd->forwardmove =
|
||||
cos(DEG2RAD(delta)) * forward + cos(DEG2RAD(delta + 90)) * side;
|
||||
cmd->sidemove =
|
||||
sin(DEG2RAD(delta)) * forward + sin(DEG2RAD(delta + 90)) * side;
|
||||
}
|
||||
cmd->forwardmove = delta_cos * forward - delta_sin * side;
|
||||
cmd->sidemove = delta_sin * forward + delta_cos * side;
|
||||
}
|
Loading…
Reference in New Issue