User:Psycommando/Guide To PlayerAnimstate
Article in progress, once its done I'll publish it on its own wiki page
This guide is meant to help you sort out the inner working of the animation system in source. It is based on the hl2mp codebase.
Overview
We'll touch a few parts:
- The Animstate ( hl2mpplayeranimstate.cpp )
- The ACT lists ( ai_activity.h, ai_activity.cpp, activitylist.cpp )
- The player model qc ( in this case the blue player from the sdk template )
- Gamemovement ( CGamemovement.cpp )
We'll see how these parts interact together in order to animate the player.
In the player
If you looked through the player code already, you'll notice that animations events sent to the player through DoAnimation are sent to other clients via tempents and then are sent to the player's animstate.
void CHL2MP_Player::DoAnimationEvent( PlayerAnimEvent_t event, int nData )
{
m_PlayerAnimState->DoAnimationEvent( event, nData );
TE_PlayerAnimEvent( this, event, nData ); // Send to any clients who can see this guy.
}
Its the animstate and not the player that issues the animations to the clientside model. However the animstates need to have its Update method called when the player thinks. The Update method is called in the hl2mp_player's PostThink() method, and takes in parameter the player's current eye angles.
void CHL2MP_Player::PostThink( void )
{
BaseClass::PostThink();
if ( GetFlags() & FL_DUCKING )
{
SetCollisionBounds( VEC_CROUCH_TRACE_MIN, VEC_CROUCH_TRACE_MAX );
}
QAngle angles = GetLocalAngles();
angles[PITCH] = 0;
SetLocalAngles( angles );
// Store the eye angles pitch so the client can compute its animation state correctly.
m_angEyeAngles = EyeAngles();
m_PlayerAnimState->Update( m_angEyeAngles[YAW], m_angEyeAngles[PITCH] );
}
These two methods are the only thing the animstate needs from the player to work.