-
Автор темы
- #1
Код:
void C_Movement::AutoStrafe()
{
C_UserCmd* pCmd = g_PacketManager->GetModifableCommand(); //
if (g_Globals.m_LocalPlayer->GetMoveType() == MOVETYPE_LADDER)
return;
if (g_Globals.m_LocalPlayer->m_fFlags() & FL_ONGROUND)
return;
static auto cl_sidespeed = g_Globals.m_Interfaces.m_CVar->FindVar(_S("cl_sidesрeed"));
auto side_speed = cl_sidespeed->GetFloat();
if (g_Settings->m_bWASDStrafe)
{
static auto old_yaw = 0.0f;
auto get_velocity_degree = [](float velocity)
{
auto tmp = RAD2DEG(atan(30.0f / velocity));
if (CheckIfNonValidNumber(tmp) tmp > 90.0f)
return 90.0f;
else if (tmp < 0.0f)
return 0.0f;
else
return tmp;
};
if (g_Globals.m_LocalPlayer->GetMoveType() != MOVETYPE_WALK)
return;
auto velocity = g_Globals.m_LocalPlayer->m_vecVelocity();
velocity.z = 0.0f;
auto forwardmove = pCmd->m_flForwardMove;
auto sidemove = pCmd->m_flSideMove;
if (velocity.Length2D() > 5.0f && !forwardmove && !sidemove)
return;
static auto flip = false;
flip = !flip;
auto turn_direction_modifier = flip ? 1.0f : -1.0f;
auto viewangles = pCmd->m_angViewAngles;
if (forwardmove sidemove)
{
pCmd->m_flForwardMove = 0.0f;
pCmd->m_flSideMove = 0.0f;
auto turn_angle = atan2(-sidemove, forwardmove);
viewangles.yaw += turn_angle * M_RADPI;
}
else if (forwardmove)
pCmd->m_flForwardMove = 0.0f;
auto strafe_angle = RAD2DEG(atan(15.0f / velocity.Length2D()));
if (strafe_angle > 90.0f)
strafe_angle = 90.0f;
else if (strafe_angle < 0.0f)
strafe_angle = 0.0f;
auto temp = Vector(0.0f, viewangles.yaw - old_yaw, 0.0f);
temp.y = normalize_yaw1(temp.y);
auto yaw_delta = temp.y;
old_yaw = viewangles.yaw;
auto abs_yaw_delta = fabs(yaw_delta);
if (abs_yaw_delta <= strafe_angle abs_yaw_delta >= 15.0f)
{
Vector velocity_angles;
vector_angles1(velocity, velocity_angles);
temp = Vector(0.0f, viewangles.yaw - velocity_angles.y, 0.0f);
temp.y = normalize_yaw1(temp.y);
auto velocityangle_yawdelta = temp.y;
auto velocity_degree = get_velocity_degree(velocity.Length2D());
if (velocityangle_yawdelta <= velocity_degree velocity.Length2D() <= 15.0f)
{
if (-velocity_degree <= velocityangle_yawdelta velocity.Length2D() <= 15.0f)
{
viewangles.yaw += strafe_angle * turn_direction_modifier;
pCmd->m_flSideMove = side_speed * turn_direction_modifier;
}
else
{
viewangles.yaw = velocity_angles.y - velocity_degree;
pCmd->m_flSideMove = side_speed;
}
}
else
{
viewangles.yaw = velocity_angles.y + velocity_degree;
pCmd->m_flSideMove = -side_speed;
}
}
else if (yaw_delta <= 0.0f)
pCmd->m_flSideMove = -side_speed;
else if (yaw_delta >= 0.0f)
pCmd->m_flSideMove = side_speed;
auto move = Vector(pCmd->m_flForwardMove, pCmd->m_flSideMove, 0.0f);
auto speed = move.Length();
Vector angles_move;
vector_angles1(move, angles_move);
auto normalized_x = fmod(pCmd->m_angViewAngles.pitch + 180.0f, 360.0f) - 180.0f;
auto normalized_y = fmod(pCmd->m_angViewAngles.yaw + 180.0f, 360.0f) - 180.0f;
auto yaw = DEG2RAD(normalized_y - viewangles.yaw + angles_move.y);
if (normalized_x >= 90.0f normalized_x <= -90.0f pCmd->m_angViewAngles.pitch >= 90.0f && pCmd->m_angViewAngles.pitch <= 200.0f pCmd->m_angViewAngles.pitch <= -90.0f && pCmd->m_angViewAngles.pitch <= 200.0f) //-V648
pCmd->m_flForwardMove = -cos(yaw) * speed;
else
pCmd->m_flForwardMove = cos(yaw) * speed;
pCmd->m_flSideMove = sin(yaw) * speed;
}
}