Game Development Community

Animating a player: playing 2 animations simultaneously

by Amr Bekhit · in Torque Game Engine · 10/21/2006 (7:09 am) · 12 replies

Hi all!

My problem lies in trying to play 2 animations on the same shape.

What I have is a player with the default animations, but I also have a custom animation (which animates the arms only) when the player fires. This animation is played using the playThread command from the ShapeBaseImage of my weapon.

The animation works fine except that when it ends, the player's arms stay in the final frame of the animation, and the rest of the body animates as it should.

I've uploaded a video to show what's going on here

Here is the code for the weapon:

//Staff Object

datablock ShapeBaseImageData(StaffImage)
{
   emap=false;
   firstPerson=true;
   shapefile="~/data/shapes/staff/staff.dts";
   mountPoint=0;
   
   
   //State machine
   
   //this state is the one the staff starts in. It goes to the next state
   //when the trigger is pressed
   stateName[0]="Ready";
   stateTransitionOnTriggerDown[0]="StartFire";
   
   //This state is used to start the animation for the helmut waving the staff
   //The playFireAnim script initias the animation
   //and the state goes to the next one when the animation reaches the point where helmut's
   //hand is in position to fire
   stateName[1]="StartFire";
   stateScript[1]="playFireAnim";
   stateTimeoutValue[1]=0.4;
   stateWaitForTimeout[1]=true;
   stateTransitionOnTimeout[1]="Fire";
   
   //This state is where the projectile is fired
   stateName[2]="Fire";
   stateTimeoutValue[2]=0.6;
   stateTransitionOnTimeout[2]="stopFire";
   
   //This is where we stop the animation
   stateName[3]="stopFire";
   stateScript[3]="stopFireAnim";
   stateTransitionOnTimeout[3]="Ready";
};

function StaffImage::playFireAnim(%this,%player)
{
   echo("\c9PLayer is Firing!");
   //Play the fire animation
   %player.playThread(1,"fire");
   //schedule(1000,0,"StaffImage::stopFireAnim");
}

function StaffImage::stopFireAnim(%this,%player)
{
   echo("\c2Player is stopping %this=" @ %this @ " player=" @ %player);
   //Stop the fire animation
   %player.stopThread(1);
}

#1
10/21/2006 (9:09 am)
You do not use the state machine that way. Take a look at the scripts provided to you. If you want to trigger a image state manually, then there is a resource for that.
#2
10/23/2006 (12:37 am)
Thanks for your reply.

No I don't want to trigger an image state manually. I'm using the Image to play this extra animation.

Which scripts do you suggest I have a peek at?

--Amr
#3
10/23/2006 (10:51 am)
It's working like it's supposed to. Just make part of your animation return to the root state, or have a "blank" animation that is the root state, and play that when you're done. Really your animation should just go back to where it started, then you shouldn't even need to "stop" it. The other method was what I used for having different "pose" sets depending on what weapon you were carrying.
#4
10/23/2006 (11:00 am)
Thanks for the tip Paul.

Just to recap, I'm playing a second animation on top of the players current animation (be that root or run or back), but when the second animation finishes, the geometry that animated remains in the last frame, whereas the rest of the body (which wasn't affected by the 2nd animation) continued animating the default player animations.

So I was wondering how adding a blank animation will that fix the problem? If I have a blank animation and play that, when the animation finishes won't it just remain in the last frame of the blank animation just like before? I already have my second animation return back to the root pose, but the problem is that it just stays there instead of relinquishing it's control over the nodes it animated.

I guess a better way of putting it would be this:

If I play an animation using playThread, I want to be able to remove any control that animation has on my model's nodes. StopThread doesn't seem to do this, as can be seen in the video above.

I'll try your method Paul, I just wanted to clarify.

--Amr
#5
10/23/2006 (3:57 pm)
Try just using setActionThread instead of playThread. setActionThread will stop playing and go back to the root animation automaticlly, it even uses nice transitions.

EDIT-
You might try making an animation called something like "armAnim", and then change the player.cc code to play that one when it plays the main root animation.

P.S. Cool helmet, ah.... with legs and arms ;)
#6
10/24/2006 (1:22 pm)
Back again,

I tried setActionThread. Unfortunatey, it doesn't seem to work while running, although it works fine when my character is in the root position :S

--Amr
#7
10/24/2006 (1:24 pm)
SetActionThread will not work with blend animations. It is mostly used for full body animations, like a death animation. playThread is broken in 1.4 but hopefully they'll fix it soon. :)
#8
10/24/2006 (1:33 pm)
Oh :( that's annoying to hear! Thanks for the info though Stefan.

Oh well...maybe a peek in the source might help...

I have to say though I think in some ways the ShapeBaseImageData is quite limited. Out of the box, it can only support the player animating a few recoil sequences and that's it. I think what needs to be done at the very least is to add a playerSequence attribute to the datablock so that the scripter can let the player animate through the Image.

I also think that the weapon system could be improved if the engine used different models for the weapon pickup, the weapon in 1st person and the weapon in 3rd person. The reason for this is so that you can use low detail models for the 3rd person and pickup, and a nice high detail model for the 1st person. Ut2004 has this system and it gives you a lot of flexibility in how you animate the weapons than the bog standard Image.

It's something I'll look into, but I'm scared of the source code! Maybe some of the more experienced C++'ers can implement this and give it away as a resource?

--Amr
#9
10/24/2006 (1:47 pm)
Quote:
I have to say though I think in some ways the ShapeBaseImageData is quite limited. Out of the box, it can only support the player animating a few recoil sequences and that's it. I think what needs to be done at the very least is to add a playerSequence attribute to the datablock so that the scripter can let the player animate through the Image.

I'm not sure what you are suggesting here.

Quote:
I also think that the weapon system could be improved if the engine used different models for the weapon pickup, the weapon in 1st person and the weapon in 3rd person. The reason for this is so that you can use low detail models for the 3rd person and pickup, and a nice high detail model for the 1st person. Ut2004 has this system and it gives you a lot of flexibility in how you animate the weapons than the bog standard Image.

There is a resource that lets you use seperate thirst/third person images trough the LOD system. If that is not enough then a few days in shapeImage might be enough to get real seperate shapes going. It looks harder than it really is, believe me.
#10
10/24/2006 (1:52 pm)
Well currently if your using a ShapeBaseImage there is no way to animate the player holding the weapon except through a couple of recoil animations. What I'm suggesting is that just like you can the animate the weapon mesh using the stateSequence property, it would be convenient to have a similar one, say statePlayerSequence that will play an animation sequence for the player.

Quote:There is a resource that lets you use seperate thirst/third person images trough the LOD system. If that is not enough then a few days in shapeImage might be enough to get real seperate shapes going.

Ah very nice. I will have a search for it.

Quote:It looks harder than it really is, believe me.

Ah well that's good to hear. I'll have a rummage in the code...

--Amr
#11
10/24/2006 (2:07 pm)
playThread is broken in 1.4 but hopefully they'll fix it soon. :)

I dont think it is.... Im using it.

i think.
#12
10/24/2006 (2:39 pm)
Quote:
playThread is broken in 1.4 but hopefully they'll fix it soon. :)

I dont think it is.... Im using it.

i think.

Aye. It works on staticShapes and whatever, but not on the player. The thread will play once and only once, and if it is cyclic it will keep going forever.

Quote:
Well currently if your using a ShapeBaseImage there is no way to animate the player holding the weapon except through a couple of recoil animations. What I'm suggesting is that just like you can the animate the weapon mesh using the stateSequence property, it would be convenient to have a similar one, say statePlayerSequence that will play an animation sequence for the player.

This is trivial to add if you take a look at the recoilThread code. That's how I did it anyway.