diff options
Diffstat (limited to 'internal_rewrite/c_base_player.cpp')
| -rw-r--r-- | internal_rewrite/c_base_player.cpp | 112 |
1 files changed, 97 insertions, 15 deletions
diff --git a/internal_rewrite/c_base_player.cpp b/internal_rewrite/c_base_player.cpp index 1d31756..24f75cd 100644 --- a/internal_rewrite/c_base_player.cpp +++ b/internal_rewrite/c_base_player.cpp @@ -649,6 +649,52 @@ void c_base_player::compute_move_cycle( bool reset, bool moving ) { void c_base_player::calc_anim_velocity( bool reset ) {
int idx = ce( )->GetIndex( );
+ auto accelerate = [ & ]( vec3_t velocity, vec3_t direction, float speed, float accel ) { + float addspeed, accelspeed, currentspeed; + + velocity.z = 0.f; + currentspeed = velocity.dot( direction ); + + addspeed = speed - currentspeed; + + if( addspeed <= 0.f ) { + return velocity; + } + + //guess how many fucks i give, this works + accelspeed = std::min( accel * 10.f * TICK_INTERVAL( ) * std::max( speed, 250.f ), currentspeed ); + + for( size_t i{ }; i < 3; ++i ) { + velocity[ i ] += accelspeed * direction[ i ]; + } + + return velocity; + }; + + auto friction = [ & ]( vec3_t velocity ) { + static auto sv_friction = g_csgo.m_cvar( )->FindVar( xors( "sv_friction" ) ); + static auto sv_stopspeed = g_csgo.m_cvar( )->FindVar( xors( "sv_stopspeed" ) ); + + float speed = velocity.length2d( ); + if( speed < 0.1f ) + return vec3_t{ }; + + float friction = sv_friction->get_float( );
+ float control = ( speed < sv_stopspeed->get_float( ) ) ? sv_stopspeed->get_float( ) : speed;
+ float drop = control * friction * TICK_INTERVAL( );
+
+ float newspeed = speed - drop;
+ if( newspeed < 0.f )
+ newspeed = 0.f;
+
+ if( newspeed != speed ) {
+ newspeed /= speed;
+ velocity *= newspeed;
+ } + + return velocity; + };
+
if( reset ) {
vec3_t velocity = m_vecVelocity( );
sm_animdata[ idx ].m_last_origin = m_vecOrigin( );
@@ -656,27 +702,55 @@ void c_base_player::calc_anim_velocity( bool reset ) { sm_animdata[ idx ].m_anim_velocity = velocity;
}
else {
+ static auto sv_accelerate = g_csgo.m_cvar( )->FindVar( xors( "sv_accelerate" ) );
+
float delta = m_flSimulationTime( ) - m_flOldSimulationTime( );
delta = std::max( delta, TICK_INTERVAL( ) );
- vec3_t origin = m_vecOrigin( );
+ bool on_ground = m_fFlags( ) & FL_ONGROUND;
+ vec3_t origin = m_vecOrigin( );
vec3_t origin_delta = origin - sm_animdata[ idx ].m_last_origin;
vec3_t velocity = origin_delta / delta;
- vec3_t last_velocity = sm_animdata[ idx ].m_last_velocity;
-
- vec3_t anim_velocity = math::lerp(
- last_velocity,
- velocity,
- TICK_INTERVAL( ) / delta );
-
- if( anim_velocity.length2d( ) < 3.f ) {
- anim_velocity.x = anim_velocity.y = 0.f;
- velocity = anim_velocity;
+ vec3_t last_velocity = sm_animdata[ idx ].m_last_velocity; + + vec3_t anim_vel; + + if( on_ground ) { + vec3_t ang = math::vector_angles( vec3_t( ), velocity ); + + float move_yaw = math::vector_angles( velocity ).y; + float move_delta = math::vector_angles( last_velocity ).y; + move_delta -= move_yaw; + move_delta = std::remainderf( move_delta, 360.f ); + + vec3_t move_dir = math::angle_vectors( vec3_t( 0.f, move_delta, 0.f ) ) * 450.f; + + vec3_t forward, right, up; + math::angle_vectors( ang, &forward, &right, &up ); + + vec3_t wishdir; + for( size_t i{ }; i < 2; ++i ) + wishdir[ i ] = forward[ i ] * move_dir.x + right[ i ] * move_dir.y; + + anim_vel = friction( last_velocity ); + if( anim_vel.length2d( ) < 15.f ) + anim_vel = vec3_t( ); + + if( anim_vel.length2d( ) >= 0.1f && velocity.length2d( ) > last_velocity.length2d( ) ) { + anim_vel = accelerate( anim_vel, wishdir, 250.f, sv_accelerate->get_float( ) ); + }
+ }
+ else {
+ anim_vel = math::lerp(
+ last_velocity,
+ velocity,
+ TICK_INTERVAL( ) / delta
+ );
}
- sm_animdata[ idx ].m_anim_velocity = anim_velocity;
+ sm_animdata[ idx ].m_anim_velocity = anim_vel;
sm_animdata[ idx ].m_last_velocity = velocity;
sm_animdata[ idx ].m_last_origin = origin;
}
@@ -798,7 +872,12 @@ void c_base_player::fix_animations( bool reset, bool resolver_change ) { sm_animdata[ idx ].m_last_duck = m_flDuckAmount( );
+ float prev_cycle = m_AnimOverlay( ).GetElements( )[ 6 ].m_flPrevCycle;
+ float prev_rate = m_AnimOverlay( ).GetElements( )[ 6 ].m_flPlaybackRate;
get_animstate( )->update( eye_angles.y, eye_angles.x );
+ m_AnimOverlay( ).GetElements( )[ 6 ].m_flPrevCycle = m_AnimOverlay( ).GetElements( )[ 6 ].m_flCycle;
+ m_AnimOverlay( ).GetElements( )[ 6 ].m_flCycle = prev_cycle + prev_rate;
+
get_animdata( ).m_prev_flags = flags;
memcpy(
@@ -830,14 +909,17 @@ void c_base_player::fix_animations( bool reset, bool resolver_change ) { bool moving = sm_animdata[ idx ].m_anim_velocity.length( ) > 0.1f;
//compute_move_cycle( reset, moving );
+
- float backup_weight = m_AnimOverlay( ).GetElements( )[ 6 ].m_flWeight;
if( is_fakewalking( ) && !reset ) {
- sm_animdata[ idx ].m_last_velocity = vec3_t( );
- sm_animdata[ idx ].m_anim_velocity = vec3_t( );
+ //sm_animdata[ idx ].m_last_velocity = vec3_t( );
+ //sm_animdata[ idx ].m_anim_velocity = vec3_t( );
}
+ if( !moving )
+ m_AnimOverlay( ).GetElements( )[ 6 ].m_flWeight = 0.f;
+
ce( )->GetRenderAngles( ).y = std::remainderf( ce( )->GetRenderAngles( ).y, 360.f );
m_flDuckAmount( ) = original_duck;
|
