User:Psycommando/Guide To PlayerAnimstate

From Valve Developer Community
Jump to navigation Jump to search
Under construction.png
This User page is actively undergoing a major edit.
As a courtesy, please do not edit this User while this message is displayed.
If this page has not been edited for at least several hours to a few days, please remove this template. This message is intended to help reduce edit conflicts; please remove it between editing sessions to allow others to edit the page.

The person who added this notice will be listed in its edit history should you wish to contact them.

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.


In the animstate

Adding a new animation