Jump to content

Home

JK2 Animation Thread


razorace

Recommended Posts

  • Replies 117
  • Created
  • Last Reply

In working on the mod I'm involved with, I've been adding animations to the game, I thought I'd share a little of what I learned in the process.

 

First off, all the animations are defined in either cgame\animtable.h or game\anims.h

 

I'm not gonna list em all here because there are at least a hundred in each. Most of em have comments beside them explaining what they do.

 

When getting an animation to play in the game you have to call a method in bg_panimate.c called PM_SetAnim. When making this call you have to pass several arguments like so:

PM_SetAnim(SETANIM_BOTH, BOTH_FORCEHEAL_START, SETANIM_FLAG_HOLD, 0);

 

This particular call performs the meditation crouch that kyle performs in the SP game at force level one.

 

The first argument is telling the method which part of the player's body to animate. There are three options to use here:

 

[*]SETANIM_TORSO

[*]SETANIM_LEGS

[*]SETANIM_BOTH

[/list=1]

 

I think these are pretty self explanitory. These constants can also be replaced by the numbers 1, 2, or 3 respectively.

 

The second argument is the actual animation to perform.

 

The third argument contains the animations flag, to be completely honest with you, I'm not sure what all these do. I have been able to figure out some though. The list of available flags:

 

[*]SETANIM_FLAG_NORMAL

[*]SETANIM_FLAG_OVERRIDE

[*]SETANIM_FLAG_HOLD

[*]SETANIM_FLAG_RESTART

[*]SETANIM_FLAG_HOLDLESS

[/list=1]

 

Normal means that you go back to normal movement after the animation has played.

 

Override means that it will override any animation that is currently playing.

 

Hold and Holdless I'm not real sure about.

 

Restart sets it so that it will be able to loop.

 

These constants can be replaced with the numbers 0, 1, 2, 4, 8 respectively.

 

The final argument is the blendtime. I'm not real sure what this is for but it doesn't matter anyway. For some reason at the beginning of the method this is set to 0 and a comment above it informs coders that it's being done purposefully but doesn't say why.

 

If you would like to hold a certain pose (like the meditation pose for heal level one). You can do so by setting the legsTimer and torsoTimer attributes like so:

 



PM_SetAnim(SETANIM_BOTH, BOTH_FORCEHEAL_START, SETANIM_FLAG_HOLD, 0);
pm->ps->legsTimer = 7000;
pm->ps->torsoTimer = 7000;

 

This will make the player perform the meditation healing pose and hold it at the last frame of the animation for seven seconds.

 

NOTE: I found out the hard way that you have to set the leg and torso timers back to 0 if you want to interupt the animation. There's nothing like watching the player jump, bust out the lightsaber, and try to swing all from the meditation stance :).

 

NOTE: While writing this short article, I found two commented out calls to a method titled NPC_SetAnim. I'm starting to get some ideas on how to control the way NPCs move around in the game :).

Link to comment
Share on other sites

It depends on the flags and the torsotimer and legstimer.

 

There's only one instance when a PM_ utility function is called in game. Search for it cos i can't remember the file atm. But it had to initialise a pmove object so it could use the PM_SetAnim.

Link to comment
Share on other sites

All the HANDEXTEND animations (force use, choking, etc) are called in bg_pmove.c in a method called PM_Weapon.

 

Ok, I just did a find in files search for "PM_" (without the quotes obviously) and the only results were located in game and cgame. Which would mean that there are no PM_ calls outside of game and cgame. Maybe I'm not understanding you. Are you saying that only one call to PM_ anything is coming from game or cgame? And that all others must come from UI? (no you didn't implicitly say ui but after game and cgame, ui is the only one left really)

Link to comment
Share on other sites

So the interruptibility is based on how the PM_SetAnim is set and not the physical animation? What's the relationship between the PM_SetAnim settings and the interruptibility of the move?

 

So if all move -> animation code is in bg_pmove.c file, do you have to create a additional function to call to from other sections of your code or does such a function already exist?

 

How does the JK2 handle animations set to "normal"? Does it place the animation in a sort of animation query or does it execute immediately after the end of the currently running animation?

 

Can you use more than one Flag in the PM_Anim function?

Link to comment
Share on other sites

Originally posted by razorace

Does that mean all animations are interruptable? I had heard that some animations were not interruptable.

 

If you want to interupt an animation (I don't know for sure if there are any that can't be interupted but I can think of some that probably are such as saber anims) make sure that leg and torso timers aren't running because they take precedence above all else. Also make sure to use the override flag or it won't be able to interupt. The override flag seems to say "I don't care what you're doing, stop now and do this", but the timers still trump even the override flag. You could always edit the PM_SetAnimFinal method in bg_panimate.c (if you pick through the code you'll find that this is the method that actually STARTS the animation, PM_SetAnim just basically does a validity check and passes it on). You could put something in like:

 

if (setAnimFlags == SETANIM_FLAG_OVERRIDE){
pm->ps->torsoTimer = 0;
pm->ps->legsTimer = 0;
}

Link to comment
Share on other sites

Originally posted by razorace

So the interruptibility is based on how the PM_SetAnim is set and not the physical animation? What's the relationship between the PM_SetAnim settings and the interruptibility of the move?

 

So if all move -> animation code is in bg_pmove.c file, do you have to create a additional function to call to from other sections of your code or does such a function already exist?

 

How does the JK2 handle animations set to "normal"? Does it place the animation in a sort of animation query or does it execute immediately after the end of the currently running animation?

 

Can you use more than one Flag in the PM_Anim function?

 

Take a look at PM_SetAnimFinal in bg_panimate.c around line 1043. This function is where the magic happens so to speak. I could be wrong but I believe that the normal flag is just what you use when you don't want to attach any special importance to the animation (such as override or restart). I can say from looking at the code that if you have an animation running and call another one without the override flag set, it ain't happening.

 

The decision on whether or not to code your own function is entirely up to you. I would recomend calling the animations from preexisting functions just to keep it simple, but that's more of a personal preference than anything.

 

I'm not really sure if you can send multiple flags, but I think you can. Take a look at the PM_Weapon function in bg_pmove.c at line 3362 (approx) it says:

 

PM_SetAnim(SETANIM_TORSO, desiredAnim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD, 100);

 

Sure looks like it to me but I haven't tried it yet.

Link to comment
Share on other sites

Originally posted by razorace

I imagine everything is interruptible as I've never seen an animation continue on death.

 

So, once you have your animation <-> moves setup, what do you do to activate the animation?

 

That's it:

 

PM_SetAnim(body location, animation, flags, blendtime);

 

and the animation will start on the next frame.

Link to comment
Share on other sites

my bad. I got confused for a minute there. :)

 

If the "normal" animation flag doesn't add to a query, that means JK2 doesn't have any sort of move query (or is located somewhere else). Therefore, you must wait until a move has started before you can start trying to do the next one. That's good to know for gameplay purposes. :)

Link to comment
Share on other sites

Wait a sec, so how do you make it so the a saber swing animation overrides the idle/movement animations but not another saber swing? Is that handled by the movement code? If so, why have the "normal" tag in the first place, wouldn't all animations interrupt every other anyway?

Link to comment
Share on other sites

When you think about it, it makes a lot of sense that way actually. You wouldn't want a player to be able to perform a bunch of keypress combos and be able to just sit back and watch his character fight would you? Or go the other way with it, during a saber fight a player may make several button presses per second, woudn't it suck if the game cached them all and made you watch while they played out?

 

But that does give me an interesting idea about how to handle in-game scenes with modeled NPCs. What if you wrote a function for each scene? Just a bunch of animation calls, and sound bytes. Something like player c does animation o then faces direction d and moves forward d msecs then faces direction j and performs animation u while playing audio file n and keels over dead because player k stabbed him in the back, played laughing animation i and playes laughing audio file e. Sounds kinda abstract but I think it could work.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...