M PlayerAnimState: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(oh well)
No edit summary
Line 5: Line 5:
:* <code>CBasePlayer::PostThink()</code>
:* <code>CBasePlayer::PostThink()</code>
:* <code>C_BasePlayer::UpdateClientSideAnimation()</code>
:* <code>C_BasePlayer::UpdateClientSideAnimation()</code>
; <code>DoAnimationEvent()</code>
; <code>DoAnimationEvent( PlayerAnimEvent_t event, int nData = 0 )</code>
: Begins a discrete, event-based animation (crouching, shooting, reloading) whenever called.
: Begins a discrete, event-based animation (crouching, shooting, reloading) whenever called. <code>PlayerAnimEvent_t</code> is an enum value that defines what type of animation event this is; it is translated into an [[activity]] elsewhere depending on the status of the player (weapon held, swimming, etc).


== Implementation ==
== Implementation ==


{{note|Your player must be using a model set up for player animation for any of this to work. ''Single-player models are not suitable''! Valve don't mind modders lifting their [[Half-Life 2: Deathmatch|HL2DM]] models, which are set up correctly.}}
{{note|Your player must be using a model set up for player animation for any of this to work. ''Single-player models are not suitable!'' Valve don't mind modders lifting their [[Half-Life 2: Deathmatch|HL2DM]] models, which are set up correctly.}}


You must define <code>m_PlayerAnimState</code> in both your client and server classes:
You must define <code>m_PlayerAnimState</code> in both your client and server classes:
Line 20: Line 20:
CMultiPlayerAnimState* m_PlayerAnimState;
CMultiPlayerAnimState* m_PlayerAnimState;
// ...
// ...
}
};
</source>
</source>



Revision as of 13:56, 31 January 2010

The m_PlayerAnimState object maintains a player's animation state. It is shared code. There are two versions, CBasePlayerAnimState and CMultiPlayerAnimState, and two entry points:

Update( float eyeYaw, float eyePitch )
Manages ambient, looping animations (running/swimming, aiming, breathing) based on player velocity and look direction every frame. Typically called from:
  • CBasePlayer::PostThink()
  • C_BasePlayer::UpdateClientSideAnimation()
DoAnimationEvent( PlayerAnimEvent_t event, int nData = 0 )
Begins a discrete, event-based animation (crouching, shooting, reloading) whenever called. PlayerAnimEvent_t is an enum value that defines what type of animation event this is; it is translated into an activity elsewhere depending on the status of the player (weapon held, swimming, etc).

Implementation

Note.pngNote:Your player must be using a model set up for player animation for any of this to work. Single-player models are not suitable! Valve don't mind modders lifting their HL2DM models, which are set up correctly.

You must define m_PlayerAnimState in both your client and server classes:

class CMyPlayerClass : public CBasePlayer
{
	// ...
	CMultiPlayerAnimState* m_PlayerAnimState;
	// ...
};

Dispatching

In multiplayer you must dispatch animation events to all onlooking clients, a job which is not performed by CBasePlayer. See m_PlayerAnimState/TempEnt for the temporary entity used by Valve.