M PlayerAnimState: Difference between revisions
Jump to navigation
Jump to search
Note:Your player must be using a model set up with the appropriate blend sequences for any of this to work. Unfortunately there are several different schemes floating around: Ep1, OB and Counter-Strike players are all driven by different sequences!
TomEdwards (talk | contribs) No edit summary |
TomEdwards (talk | contribs) (more implementation: still not working, but closer!) |
||
Line 7: | Line 7: | ||
; <code>DoAnimationEvent( PlayerAnimEvent_t event, int nData = 0 )</code> | ; <code>DoAnimationEvent( PlayerAnimEvent_t event, int nData = 0 )</code> | ||
: 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). | : 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). | ||
{{note|Your player must be using a model set up with the appropriate [[blend sequence]]s for any of this to work. Unfortunately there are several different schemes floating around: Ep1, OB and Counter-Strike players are all driven by different sequences!}} | |||
== Implementation == | == Implementation == | ||
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: | ||
<source lang=cpp> | <source lang=cpp> | ||
class CMyPlayerClass : public CBasePlayer | class CMyPlayerClass : public CBasePlayer // and on client! | ||
{ | { | ||
// ... | // ... | ||
Line 23: | Line 23: | ||
</source> | </source> | ||
=== Dispatching === | And then initialise it in shared code: | ||
<source lang=cpp> | |||
inline void CMyPlayerClass::Spawn_Shared() | |||
{ | |||
MultiPlayerMovementData_t mv; | |||
mv.m_flSprintSpeed = -1; | |||
mv.m_flRunSpeed = 200; | |||
mv.m_flWalkSpeed = 80; | |||
mv.m_flBodyYawRate = 180; | |||
m_PlayerAnimState = new CMultiPlayerAnimState( this,mv ); | |||
} | |||
</source> | |||
Now you need to hook things up. On the server: | |||
<source lang=cpp> | |||
void CMyPlayerClass::PostThink() | |||
{ | |||
BaseClass::PostThink(); | |||
// Keep the model upright; pose params will handle pitch aiming. | |||
QAngle angles = GetLocalAngles(); | |||
angles[PITCH] = 0; | |||
SetLocalAngles( angles ); | |||
m_PlayerAnimState->Update( EyeAngles()[YAW], EyeAngles()[PITCH] ); | |||
} | |||
</source> | |||
And on the client: | |||
<source lang=cpp> | |||
void C_MyPlayerClass::UpdateClientSideAnimation() | |||
{ | |||
m_PlayerAnimState->Update( EyeAngles()[YAW], EyeAngles()[PITCH] ); | |||
} | |||
</source> | |||
=== Dispatching to clients === | |||
In multiplayer you must dispatch animation events to all onlooking clients, a job which is not performed by <code>CBasePlayer</code>. See [[m_PlayerAnimState/TempEnt]] for the temporary entity used by Valve. | In multiplayer you must dispatch animation events to all onlooking clients, a job which is not performed by <code>CBasePlayer</code>. See [[m_PlayerAnimState/TempEnt]] for the temporary entity used by Valve. | ||
[[Category:CBasePlayer]] {{DISPLAYTITLE:m_PlayerAnimState}} | [[Category:CBasePlayer]] {{DISPLAYTITLE:m_PlayerAnimState}} |
Revision as of 09:24, 1 February 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
You must define m_PlayerAnimState
in both your client and server classes:
class CMyPlayerClass : public CBasePlayer // and on client!
{
// ...
CMultiPlayerAnimState* m_PlayerAnimState;
// ...
};
And then initialise it in shared code:
inline void CMyPlayerClass::Spawn_Shared()
{
MultiPlayerMovementData_t mv;
mv.m_flSprintSpeed = -1;
mv.m_flRunSpeed = 200;
mv.m_flWalkSpeed = 80;
mv.m_flBodyYawRate = 180;
m_PlayerAnimState = new CMultiPlayerAnimState( this,mv );
}
Now you need to hook things up. On the server:
void CMyPlayerClass::PostThink()
{
BaseClass::PostThink();
// Keep the model upright; pose params will handle pitch aiming.
QAngle angles = GetLocalAngles();
angles[PITCH] = 0;
SetLocalAngles( angles );
m_PlayerAnimState->Update( EyeAngles()[YAW], EyeAngles()[PITCH] );
}
And on the client:
void C_MyPlayerClass::UpdateClientSideAnimation()
{
m_PlayerAnimState->Update( EyeAngles()[YAW], EyeAngles()[PITCH] );
}
Dispatching to clients
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.