Hi! How can I increase my strafe speed to around 800 ?
Now I get about ~700 with sv_airaccelerate value of 100 .
Now I get about ~700 with sv_airaccelerate value of 100 .
стрейфа:
void CMovement::DirectionalAirStrafe(Vector vVelocity, float flCurrentSpeed, float flFrameTime, bool bSubtickCalling) {
if (!Config::b(g_Variables.m_Movement.m_bEnableAutoStrafe))
return;
CONVAR(sv_airaccelerate);
CONVAR(sv_air_max_wishspeed);
auto pBase = Globals::m_pBaseCmd;
auto pMoveService = Globals::m_pLocalPlayerPawn->m_pMovementServices();
static uint64_t uLastPressed = 0;
static uint64_t uLastButtons = 0;
const uint64_t uCurrentButtons = Globals::m_pCmd->m_nButtons.m_nValue;
const auto CheckButton = [&](const uint64_t uButton)
{
if (uCurrentButtons & uButton && (!(uLastButtons & uButton)
|| (uButton & IN_MOVELEFT && !(uLastPressed & IN_MOVERIGHT))
|| (uButton & IN_MOVERIGHT && !(uLastPressed & IN_MOVELEFT))
|| (uButton & IN_FORWARD && !(uLastPressed & IN_BACK))
|| (uButton & IN_BACK && !(uLastPressed & IN_FORWARD))))
{
if (uButton & IN_MOVELEFT)
uLastPressed &= ~IN_MOVERIGHT;
else if (uButton & IN_MOVERIGHT)
uLastPressed &= ~IN_MOVELEFT;
else if (uButton & IN_FORWARD)
uLastPressed &= ~IN_BACK;
else if (uButton & IN_BACK)
uLastPressed &= ~IN_FORWARD;
uLastPressed |= uButton;
}
else if (!(uCurrentButtons & uButton))
uLastPressed &= ~uButton;
};
CheckButton(IN_MOVELEFT);
CheckButton(IN_MOVERIGHT);
CheckButton(IN_FORWARD);
CheckButton(IN_BACK);
uLastButtons = uCurrentButtons;
if (uCurrentButtons & IN_SPRINT || Globals::m_pLocalPlayerPawn->m_nActualMoveType() == MOVETYPE_LADDER ||
Globals::m_pLocalPlayerPawn->m_nActualMoveType() == MOVETYPE_NOCLIP ||
g_Prediction->GetPostFlags() & FL_ONGROUND ||
g_Prediction->GetPreFlags() & FL_ONGROUND)
return;
float flOffset = 0.f;
if (uLastPressed & IN_MOVELEFT)
flOffset += 90.f;
if (uLastPressed & IN_MOVERIGHT)
flOffset -= 90.f;
if (uLastPressed & IN_FORWARD)
flOffset *= 0.5f;
else if (uLastPressed & IN_BACK)
flOffset = -flOffset * 0.5f + 180.f;
float flYaw = Math::FloatNormalize(Interfaces::m_pInput->GetViewAngles().y);
flYaw += flOffset;
pBase->set_forwardmove(0.f);
pBase->set_leftmove(0.f);
const float flVelocityAngle = Math::FloatNormalize(M_RAD2DEG(atan2f(vVelocity.y, vVelocity.x)));
const float flSpeed = vVelocity.Length2D();
const auto flIdeal = std::clamp(
M_RAD2DEG(
atan(
fmax(
15.f,
30.f - (
flCurrentSpeed *
sv_airaccelerate->GetFloat() *
pMoveService->m_flSurfaceFriction() *
flFrameTime
)
) / flSpeed
)
),
0.f,
45.f
);
const float flVelocityDelta = Math::FloatNormalize(flYaw - flVelocityAngle);
auto RotateMovement = [](CUserCmd* pCmd, CBaseUserCmdPB* pBaseCmd, float flTargetYaw)
{
const float flRotation = M_DEG2RAD(pBaseCmd->viewangles().y() - flTargetYaw);
const float flNewForwardMove = cos(flRotation) * pBaseCmd->forwardmove() - sin(flRotation) * pBaseCmd->leftmove();
const float flNewSideMove = sin(flRotation) * pBaseCmd->forwardmove() + cos(flRotation) * pBaseCmd->leftmove();
pBaseCmd->set_forwardmove(std::clamp(flNewForwardMove, -1.f, 1.f));
pBaseCmd->set_leftmove(std::clamp(flNewSideMove * -1.f, -1.f, 1.f));
};
if ((fabsf(flVelocityDelta) > 170.f && flSpeed > 80.f) || (flVelocityDelta > flIdeal && flSpeed > 80.f))
{
flYaw = flIdeal + flVelocityAngle;
pBase->set_leftmove(-1.f);
RotateMovement(Globals::m_pCmd, pBase, Math::FloatNormalize(flYaw));
return;
}
static bool bSideSwitch = false;
bSideSwitch = bSubtickCalling ? !bSideSwitch : Globals::nSequence % 2 == 0;
if (-flIdeal <= flVelocityDelta || flSpeed <= 80.f) {
if (bSideSwitch) {
flYaw = flYaw - flIdeal;
pBase->set_leftmove(-1.f);
}
else {
flYaw = flIdeal + flYaw;
pBase->set_leftmove(1.f);
}
}
else {
flYaw = flVelocityAngle - flIdeal;
pBase->set_leftmove(1.f);
}
RotateMovement(Globals::m_pCmd, pBase, flYaw);
if (!bSubtickCalling && Config::b(g_Variables.m_Movement.m_bEnableAutoStrafe)) {
this->SubtickAirStrafe();
}
}
void CMovement::AirAccelerate(Vector& vVelocity, Vector vMoveImpulse, float& flStamina, float flFrameTime, float flYaw)
{
CONVAR(sv_airaccelerate);
CONVAR(sv_staminarecoveryrate);
CONVAR(sv_air_max_wishspeed);
float flCurrentSpeed = vVelocity.Length2D();
if (flStamina > 0)
{
float flSpeedScale = std::clamp(1.0f - (flStamina / 100.f), 0.f, 1.f);
flCurrentSpeed *= flSpeedScale * flSpeedScale;
flStamina = fmaxf(flStamina - (flFrameTime * sv_staminarecoveryrate->GetFloat()), 0.f);
}
QAngle angViewAngles = { 0, flYaw, 0 };
Vector vecForward, vecLeft, vecUp;
angViewAngles.ToDirections(&vecForward, &vecLeft, &vecUp);
vecForward.NormalizeInPlace();
vecLeft.NormalizeInPlace();
Vector vecWishDir(
((vecForward.x * vMoveImpulse.x) * flCurrentSpeed) - ((vecLeft.x * vMoveImpulse.y) * flCurrentSpeed),
((vecForward.y * vMoveImpulse.x) * flCurrentSpeed) - ((vecLeft.y * vMoveImpulse.y) * flCurrentSpeed),
0.f
);
float flWishSpeed = vecWishDir.NormalizeInPlace();
flWishSpeed = fminf(flWishSpeed, flCurrentSpeed);
const float flSpeedAdd = fminf(flWishSpeed, sv_air_max_wishspeed->GetFloat() - vVelocity.DotProduct(vecWishDir));
if (flSpeedAdd < 0.f)
return;
const float flAccelSpeed = fminf(flSpeedAdd, flWishSpeed * flFrameTime * sv_airaccelerate->GetFloat());
vVelocity += (vecWishDir * flAccelSpeed) * 0.4f;
}
void CMovement::SubtickAirStrafe()
{
CONVAR(sv_gravity);
if (Globals::m_pLocalPlayerPawn->m_nActualMoveType() == MOVETYPE_LADDER ||
Globals::m_pLocalPlayerPawn->m_nActualMoveType() == MOVETYPE_NOCLIP ||
(g_Prediction->GetPostFlags() & FL_ONGROUND) ||
(g_Prediction->GetPreFlags() & FL_ONGROUND) ||
(Globals::m_pLocalPlayerPawn->m_fFlags() & FL_ONGROUND))
return;
auto pBase = Globals::m_pBaseCmd;
auto pLocal = Globals::m_pLocalPlayerPawn;
auto pMoveService = pLocal->m_pMovementServices();
float flFriction = pMoveService->m_flSurfaceFriction();
float flStamina = pMoveService->m_flStamina();
Vector vAbsVelocity = pLocal->m_vecAbsVelocity();
Vector vLastImpulses = pMoveService->m_vecLastMovementImpulses();
Vector vCMDMoveBackup = { pBase->forwardmove(), pBase->leftmove(), pBase->upmove() };
const int nTicks = std::clamp(12 - pBase->subtick_moves_size(), 0, 12);
const float flFrameTime = INTERVAL_PER_TICK / static_cast<float>(nTicks);
float flMovementYaw = this->m_angModelAngles.y;
for (int i = 0; i < nTicks; ++i)
{
const auto& pSubtick = Interfaces::m_pInput->CreateNewSubTickMoveStep(pBase->mutable_subtick_moves());
if (!pSubtick)
continue;
pBase->set_forwardmove(vCMDMoveBackup.x);
pBase->set_leftmove(vCMDMoveBackup.y);
pBase->set_upmove(vCMDMoveBackup.z);
this->AirAccelerate(vAbsVelocity, vLastImpulses, flStamina, flFrameTime, flMovementYaw);
if (this->m_bWants2DMoveHalt) {
this->StopMovement();
this->MovementCorrection();
}
else {
this->DirectionalAirStrafe(vAbsVelocity, vAbsVelocity.Length2D(), flFrameTime, true);
}
pSubtick->set_when(static_cast<float>(i) / static_cast<float>(nTicks));
pSubtick->set_analog_forward_delta(pBase->forwardmove() - vLastImpulses.x);
pSubtick->set_analog_left_delta(pBase->leftmove() - vLastImpulses.y);
//pSubtick->set_pitch_delta(m_angModelAngles.x - vCMDMoveBackup.x);
//pSubtick->set_yaw_delta(m_angModelAngles.y - vCMDMoveBackup.y);
pSubtick->set_button(0);
pSubtick->set_pressed(false);
vLastImpulses.x += pSubtick->analog_forward_delta();
vLastImpulses.y += pSubtick->analog_left_delta();
pBase->mutable_subtick_moves()->AddAllocated(pSubtick);
}
}