How to play an animation

Grab your favourite IDE and tinker with the innards of game engines

How to play an animation

Postby netserk on Wed May 16, 2007 8:08 am

How do I play a specific animation from the code in the game. In my animation-model.qc file I have the following
...
$sequence Swing_Weapon "Swing_Animation" activity ACT_SWING 2
...
I can see the animation in the modelviewer and now I want the animation to be shown in the game at certain points in the code. To make this work I have tried to add the ACT_SWING to the ai_activity.cpp. What method do I need to call to play the animation?
netserk
Member
Member
 
Joined: Sun May 13, 2007 12:39 pm
Location: Aalborg, Denmark

Postby SlappyBag on Wed May 16, 2007 11:18 am

You need to use a scripted_sequence and tell the AI to go there and play the said animation.

I NEED TO GO AND POOP!
User avatar
SlappyBag
Veteran
Veteran
 
Joined: Sun Jun 26, 2005 9:16 am
Location: Brighton, UK

Postby netserk on Wed May 16, 2007 12:37 pm

I can't use a scripted sequence. The animation is for the player character that is seen in third person. I have used the ACT_RUN, ACT_IDLE and ACT_JUMP to my own run, idle and jump animations nut also need another custom animation in specific situations.
netserk
Member
Member
 
Joined: Sun May 13, 2007 12:39 pm
Location: Aalborg, Denmark

Postby ChopperDave on Wed May 16, 2007 1:35 pm

SetActivity()? I don't have the source code in front of me right now but I'm guessing that's the kind of thing that you're looking for.
User avatar
ChopperDave
Rockstar San Diego
 
Joined: Wed Feb 21, 2007 6:06 pm

Postby netserk on Wed May 16, 2007 1:47 pm

I have tried that, but it doesn't work. what files should I include.
netserk
Member
Member
 
Joined: Sun May 13, 2007 12:39 pm
Location: Aalborg, Denmark

Postby ChopperDave on Wed May 16, 2007 1:54 pm

There's another place you need to add the activity IIRC. I'm not sure what file it's in, but the macro is something like ADD_ACTIVITY_TO_SR() or something like that.

The easiest thing to do is to find an existing activity (like ACT_RANGE_ATTACK1), search across the entire codebase, see where it's declared and such, and mimic that. If that doesn't work, can you post some more code (i.e. the snippet where you are trying to use the anim and where you declared it as well)?
User avatar
ChopperDave
Rockstar San Diego
 
Joined: Wed Feb 21, 2007 6:06 pm

Postby longshanks on Wed May 16, 2007 7:44 pm

Animations are a bit of a pain. In my mod, I added them to the registers (which is three files I believe, ai_activity.cpp and ai_activity.h, and activitylist.cpp or something) then in my player class I looked under the SetAnimation function and added in my new animations, something like this:

Code: Select all
else if ( playerAnim == PLAYER_ATTACK2 )
{
idealActivity = ACT_HL2MP_ATTACK2;
}



Code: Select all
else if ( idealActivity == ACT_HL2MP_ATTACK2 )
   {
      RestartGesture( Weapon_TranslateActivity( idealActivity ) );
      return;
   }


Then inside my weapon activity tables I override ACT_HL2MP_ATTACK2 with my custom animation..

I know that's kind of a vague explanation but maybe it will get you somewhere.
longshanks
Turbine Entertainment Software
 
Joined: Mon Nov 14, 2005 11:39 pm
Location: BOSTON!!!

Postby netserk on Thu May 17, 2007 10:39 am

Thanks for helping. Now I it almost works. The animations are shown but the game lags like hell due to assertions. I will show all code I have added/changed to make the animation works.

I have this sequence in my .qc file:

Code: Select all
$sequence Cast_CastLaunch "poet_cast_launch" activity ACT_LAUNCH 2


which is a animation of the avator launching an attack.

First I added a "ACT_LAUNCH" to the lists in ai_activity.h, ai_activity.cpp and activitylist.cpp. In the "enum PLAYER_ANIM" in shareddefs.h I added "PLAYER_ATTACK2".
I should mention that the game I am working on is seen from a third person view and that I have followed this tutorial (http://developer.valvesoftware.com/wiki ... son_Camera) to fix the this, which works perfectly.
In the HL2_Player.cpp I have added

Code: Select all
else if ( playerAnim == PLAYER_ATTACK2 )
{
   idealActivity = ACT_LAUNCH;
}


and

Code: Select all
else if ( idealActivity == ACT_LAUNCH )
{
   RestartGesture( Weapon_TranslateActivity( idealActivity ) );
          return;
}



I don't understand much of the last code "RestartGesture( ... )".
In the code where the player-avatar launches his attach I added tis line

Code: Select all
UTIL_GetLocalPlayer()->SetAnimation( PLAYER_ATTACK2 );


When I run this the animation is showed as it should but the I get the following assertions. I get them right after the game starts and I continue to get them like every frame or so untill the game ends.

Clientleafsystem.cpp (330) : Assertion Failed: absMins.IsValid() && absMaxs.IsValid()
Clientleafsystem.cpp (1026) : Assertion Failed: absMins.IsValid() && absMaxs.IsValid()
studio.h (1352) : Assertion Failed: i >= 0 && i < numbones

It seems to be something wrong with the rendering.
Can I just delete the assertions and ignore it or should I fix something?
What does the RestartGesture( Weapon_TranslateActivity( idealActivity ) ); do?
netserk
Member
Member
 
Joined: Sun May 13, 2007 12:39 pm
Location: Aalborg, Denmark

Return to Programming

Who is online

Users browsing this forum: No registered users