-
Автор темы
- #1
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Код:
void FixVelocity(player_t* m_player, adjust_data* record, adjust_data* previous, float max_speed) {
if (!previous) {
if (record->layers[6].m_flPlaybackRate > 0.0f && record->layers[6].m_flWeight != 0.f && record->velocity.Length() > 0.1f) {
auto v30 = max_speed;
if (record->flags & 6)
v30 *= 0.34f;
else if (m_player->m_bIsWalking())
v30 *= 0.52f;
auto v35 = record->layers[6].m_flWeight * v30;
record->velocity *= v35 / record->velocity.Length();
}
else
record->velocity.Zero();
if (record->flags & 1)
record->velocity.z = 0.f;
record->m_anim_velocity = record->velocity;
return;
}
if ((m_player->m_fEffects() & 8) != 0
|| m_player->m_ubEFNoInterpParity() != m_player->m_ubEFNoInterpParityOld()) {
record->velocity.Zero();
record->m_anim_velocity.Zero();
return;
}
auto is_jumping = !(record->flags & FL_ONGROUND && previous->flags & FL_ONGROUND);
if (record->m_lag > 1) {
record->velocity.Zero();
auto origin_delta = (record->origin - previous->origin);
if (!(previous->flags & FL_ONGROUND || record->flags & FL_ONGROUND))// if not previous on ground or on ground
{
auto currently_ducking = record->flags & FL_DUCKING;
if ((previous->flags & FL_DUCKING) != currently_ducking) {
float duck_modifier = 0.f;
if (currently_ducking)
duck_modifier = 9.f;
else
duck_modifier = -9.f;
origin_delta.z -= duck_modifier;
}
}
auto sqrt_delta = origin_delta.Length2DSqr();
if (sqrt_delta > 0.f && sqrt_delta < 1000000.f)
record->velocity = origin_delta / TICKS_TO_TIME(record->m_lag);
record->velocity.validate_vec();
if (is_jumping) {
if (record->flags & FL_ONGROUND && !m_cvar()->FindVar(XOR("sv_enablebunnyhopping"))->GetInt()) {
// 260 x 1.1 = 286 units/s.
float max = m_player->m_flMaxspeed() * 1.1f;
// get current velocity.
float speed = record->velocity.Length();
// reset velocity to 286 units/s.
if (max > 0.f && speed > max)
record->velocity *= (max / speed);
}
// assume the player is bunnyhopping here so set the upwards impulse.
record->velocity.z = m_cvar()->FindVar(XOR("sv_jump_impulse"))->GetFloat();
}
// we are not on the ground
// apply gravity and airaccel.
else if (!(record->flags & FL_ONGROUND)) {
// apply one tick of gravity.
record->velocity.z -= m_cvar()->FindVar(XOR("sv_gravity"))->GetFloat() * m_globals()->m_intervalpertick;
}
}
record->m_anim_velocity = record->velocity;
if (!record->m_fake_walk) {
if (record->m_anim_velocity.Length2D() > 0 && (record->flags & FL_ONGROUND)) {
float anim_speed = 0.f;
if (!is_jumping
&& record->layers[11].m_flWeight > 0.0f
&& record->layers[11].m_flWeight < 1.0f
&& record->layers[11].m_flPlaybackRate == previous->layers[11].m_flPlaybackRate) {
// calculate animation speed yielded by anim overlays
auto flAnimModifier = 0.35f * (1.0f - record->layers[11].m_flWeight);
if (flAnimModifier > 0.0f && flAnimModifier < 1.0f)
anim_speed = max_speed * (flAnimModifier + 0.55f);
}
// this velocity is valid ONLY IN ANIMFIX UPDATE TICK!!!
// so don't store it to record as m_vecVelocity
// -L3D451R7
if (anim_speed > 0.0f) {
anim_speed /= record->m_anim_velocity.Length2D();
record->m_anim_velocity.x *= anim_speed;
record->m_anim_velocity.y *= anim_speed;
}
}
}
else
record->m_anim_velocity.Zero();
record->m_anim_velocity.validate_vec();
}