User:Psycommando/Guide To PlayerAnimstate

From Valve Developer Community
Jump to: navigation, search
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.


In the animstate

Using a new animation

In this section we'll be adding a sprinting state to our player animations. Adding a new state like this will require us to make small changes to the game movement and player code along with changes to weapons acttable.

This is all somewhat simple to do.

Using a model with sprint anims

The blue and red player that comes in the source sdk's content folder are perfect for us. Just copy the source files from "Source SDK Content/sdk/player" to your mod's "modelsrc" folder.

Try compiling the "modelsrc/player/playerplayer_shared"

See also