-
Автор темы
- #1
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Код:
void airstrafe::create_move(CUserCmd* m_pcmd, Vector wish_yaw)
{
Vector velocity;
float delta, abs_delta, velocity_delta, correct, m_speed, m_ideal, m_old_yaw;
float m_switch_value = 1.f;
if (g_cfg.misc.airstrafe == 2)
{
// don't strafe while noclipping or on ladders..
if (g_ctx.local()->get_move_type() == MOVETYPE_NOCLIP || g_ctx.local()->get_move_type() == MOVETYPE_LADDER)
return;
// disable strafing while pressing shift.
// don't strafe if not holding primary jump key.
if ((m_pcmd->m_buttons & IN_SPEED) || !(m_pcmd->m_buttons & IN_JUMP) || (g_ctx.local()->m_fFlags() & FL_ONGROUND))
return;
// get networked velocity ( maybe absvelocity better here? ).
// meh, should be predicted anyway? ill see.
velocity = g_ctx.local()->m_vecVelocity();
// get the velocity len2d ( speed ).
m_speed = velocity.Length2D();
// compute the ideal strafe angle for our velocity.
m_ideal = (m_speed > 0.f) ? RAD2DEG(asin(15.f / m_speed)) : 90.f;
// some additional sanity.
math::clamp(m_ideal, 0.f, 90.f);
// for changing direction.
// we want to change strafe direction every call.
m_switch_value *= -1.f;
bool m_pressing_move = ((m_pcmd->m_buttons & IN_LEFT) || (m_pcmd->m_buttons & IN_FORWARD) || (m_pcmd->m_buttons & IN_BACK) || (m_pcmd->m_buttons & IN_RIGHT) || (m_pcmd->m_buttons & IN_MOVELEFT) || (m_pcmd->m_buttons & IN_MOVERIGHT) || (m_pcmd->m_buttons & IN_JUMP));
if (m_pressing_move)
{
// get our key presses.
bool holding_w = m_pcmd->m_buttons & IN_FORWARD;
bool holding_a = m_pcmd->m_buttons & IN_MOVELEFT;
bool holding_s = m_pcmd->m_buttons & IN_BACK;
bool holding_d = m_pcmd->m_buttons & IN_MOVERIGHT;
float direction{ };
// move in the appropriate direction.
if (holding_w) {
if (holding_a)
direction += 45.f;
else if (holding_d)
direction -= 45.f;
}
else if (holding_s) {
if (holding_a)
direction += 135.f;
else if (holding_d)
direction -= 135.f;
else
direction += 180.f;
}
else if (holding_a)
direction += 90.f;
else if (holding_d)
direction -= 90.f;
wish_yaw.y = math::normalize_yaw(wish_yaw.y + direction);
}
// cancel out any forwardmove values.
m_pcmd->m_forwardmove = 0.f;
// get our viewangle change.
delta = math::normalize_yaw(wish_yaw.y - m_old_yaw);
// convert to absolute change.
abs_delta = abs(delta);
// save old yaw for next call.
m_old_yaw = wish_yaw.y;
// set strafe direction based on mouse direction change.
if (delta > 0.f)
m_pcmd->m_sidemove = -450.f;
else if (delta < 0.f)
m_pcmd->m_sidemove = 450.f;
// we can accelerate more, because we strafed less then needed
// or we got of track and need to be retracked.
if (abs_delta <= m_ideal || abs_delta >= 30.f)
{
// compute angle of the direction we are traveling in.
QAngle velocity_angle;
math::VectorAngles(velocity, velocity_angle);
// get the delta between our direction and where we are looking at.
velocity_delta = math::normalize_yaw(wish_yaw.y - velocity_angle.yaw);
// correct our strafe amongst the path of a circle.
correct = m_ideal;
if (velocity_delta <= correct || m_speed <= 15.f)
{
// not moving mouse, switch strafe every tick.
if (-correct <= velocity_delta || m_speed <= 15.f) {
wish_yaw.y += (m_ideal * m_switch_value);
m_pcmd->m_sidemove = 450.f * m_switch_value;
}
else {
wish_yaw.y = velocity_angle.yaw - correct;
m_pcmd->m_sidemove = 450.f;
}
}
else {
wish_yaw.y = velocity_angle.yaw + correct;
m_pcmd->m_sidemove = -450.f;
}
}
}
}