-
Автор темы
- #1
You may want to remove the highlighted code.
Hardcode
C++:
void Movement::Strafe( ) {
vec3_t velocity;
float delta, abs_delta, velocity_angle, velocity_delta, correct;
// don't strafe while noclipping or on ladders..
if( g_cl.m_local->m_MoveType( ) == MOVETYPE_NOCLIP || g_cl.m_local->m_MoveType( ) == MOVETYPE_LADDER )
return;
CUserCmd* pCmd = g_cl.m_cmd;
// disable strafing while pressing shift.
// don't strafe if not holding primary jump key.
if( ( g_cl.m_buttons & IN_SPEED ) || !( g_cl.m_buttons & IN_JUMP ) || ( g_cl.m_flags & FL_ONGROUND ) )
return;
// jumpscout.
if( g_input.GetKeyState( g_menu.main.movement.fakewalk.get( ) ) || !g_cl.m_pressing_move ) {
FullStop( );
return;
}
// wasd strafer.
if (!g_menu.main.movement.autostrafedir.get())
return;
static bool bFlip = true;
static float flOldYaw = pCmd->m_view_angles.y;
vec3_t vecVelocity = g_cl.m_local->m_vecVelocity();
vecVelocity.z = 0.0f;
float_t flForwardMove = pCmd->m_forward_move;
float_t flSideMove = pCmd->m_side_move;
if (g_cl.m_local->m_vecVelocity().length_2d() <= 5.0f && !flForwardMove && !flSideMove)
return;
float flTurnVelocityModifier = bFlip ? 1.f : -1.f;
ang_t angViewAngles = pCmd->m_view_angles;
if (flForwardMove || flSideMove)
{
pCmd->m_forward_move = 0.0f;
pCmd->m_side_move = 0.0f;
float m_flTurnAngle = math::rad_to_deg(atan2f(-flSideMove, flForwardMove));
auto ahsh = angViewAngles.y + m_flTurnAngle;
math::NormalizedAngle(ahsh);
angViewAngles.y = ahsh;
}
else if (flForwardMove > 0.f)
pCmd->m_forward_move = 0.0f;
//if (vecVelocity.Length2D() <= 0.f)
//pCmd->m_forward_move = 450.f;
auto get_velocity_degree = [](const float length_2d)
{
auto tmp = math::rad_to_deg(atan2(15.f, length_2d));
return math::Clamp(tmp, 0.f, 90.f); //Math::clamp(tmp, 0.f, 90.f);
};
float flStrafeAngle = math::Clamp(math::rad_to_deg(atanf(15.0f / vecVelocity.length_2d())), 0.f, 90.f);
float flYawDelta = math::NormalizedAngle(angViewAngles.y - flOldYaw);
flOldYaw = angViewAngles.y;
float flAbsYawDelta = abs(flYawDelta);
if (flAbsYawDelta <= flStrafeAngle || flAbsYawDelta >= 15.0f)
{
ang_t angVelocityAngle;
math::VectorAngles(vecVelocity, angVelocityAngle);
float flVelocityAngleYawDelta = math::NormalizedAngle(angViewAngles.y - angVelocityAngle.y);
float flVelocityDegree = get_velocity_degree(vecVelocity.length_2d());
if (flVelocityAngleYawDelta <= flVelocityDegree || vecVelocity.length_2d() <= 15.0f)
{
if (-flVelocityDegree <= flVelocityAngleYawDelta || vecVelocity.length_2d() <= 15.0f)
{
angViewAngles.y += flStrafeAngle * flTurnVelocityModifier;
pCmd->m_side_move = 450.0f * flTurnVelocityModifier;
}
else
{
angViewAngles.y = angVelocityAngle.y - flVelocityDegree;
pCmd->m_side_move = 450.0f;
}
}
else
{
angViewAngles.y = angVelocityAngle.y + flVelocityDegree;
pCmd->m_side_move = -450.0f;
}
}
else if (flYawDelta > 0.0f)
pCmd->m_side_move = -450.0f;
else if (flYawDelta < 0.0f)
pCmd->m_side_move = 450.0f;
vec3_t vecMove = vec3_t(pCmd->m_forward_move, pCmd->m_side_move, 0.0f);
float flSpeed = vecMove.length();
ang_t angMoveAngle;
math::VectorAngles(vecMove, angMoveAngle);
float flNormalizedX = fmod(pCmd->m_view_angles.x + 180.0f, 360.0f) - 180.0f;
float flNormalizedY = fmod(pCmd->m_view_angles.y + 180.0f, 360.0f) - 180.0f;
float flYaw = math::deg_to_rad((flNormalizedY - angViewAngles.y) + angMoveAngle.y);
if (pCmd->m_view_angles.x <= 200.0f && (flNormalizedX >= 90.0f || flNormalizedX <= -90.0f || (pCmd->m_view_angles.x >= 90.0f && pCmd->m_view_angles.x <= 200.0f) || pCmd->m_view_angles.x <= -90.0f))
pCmd->m_forward_move = -cos(flYaw) * flSpeed;
else
pCmd->m_forward_move = cos(flYaw) * flSpeed;
pCmd->m_side_move = sin(flYaw) * flSpeed;
bFlip = !bFlip;
}