How to play animations properly
by Ingo Seidel · in Torque Game Engine Advanced · 06/02/2009 (8:20 am) · 14 replies
Hi,
I want to play certain animations on player objects directly from the C++ code. I have tried the playThread and setActionThread methods. When using the playThread method, the player will get "stuck" in the animation after it has finished playing. The setActionThread method generally plays the animation properly. However, when using the setActionThread method, the animations are only sometimes played while they are sometimes not played. What is the problem here, why aren't they played every time the setActionThread method is called, what can I do about this?
Furthermore, the forceSet variable in the setActionThread method seems to have no effect. If I have understood correctly, the forceSet varialbe should be used to indicate if the currently playing thread should be aborted or not. However, if forceSet=true, the old animation will still continue until it is finished and will not be interrupted by the new animation. The new animation will not be played.
thanks
I want to play certain animations on player objects directly from the C++ code. I have tried the playThread and setActionThread methods. When using the playThread method, the player will get "stuck" in the animation after it has finished playing. The setActionThread method generally plays the animation properly. However, when using the setActionThread method, the animations are only sometimes played while they are sometimes not played. What is the problem here, why aren't they played every time the setActionThread method is called, what can I do about this?
Furthermore, the forceSet variable in the setActionThread method seems to have no effect. If I have understood correctly, the forceSet varialbe should be used to indicate if the currently playing thread should be aborted or not. However, if forceSet=true, the old animation will still continue until it is finished and will not be interrupted by the new animation. The new animation will not be played.
thanks
#2
> When you play a second sequence,the main animation thread is already
> occupied,unless you have a high priority.
But isn't that what the forceSet variable is supposed to do, i.e. forceSet=true => interrupt the current thread, play the new one; forceSet=false => don't interrupt the current thread if one is playing. And still, why won't it play the animation sometimes? I call setActionThread, but the animation just doesn't get played, although the player is just standing around.
> If you want to play a lot of sequences simultaneously,you need to create additional threads.
How can I create additional threads without having to modify the Player.cpp class?
06/02/2009 (9:30 am)
> A thread can handle a single sequence.> When you play a second sequence,the main animation thread is already
> occupied,unless you have a high priority.
But isn't that what the forceSet variable is supposed to do, i.e. forceSet=true => interrupt the current thread, play the new one; forceSet=false => don't interrupt the current thread if one is playing. And still, why won't it play the animation sometimes? I call setActionThread, but the animation just doesn't get played, although the player is just standing around.
> If you want to play a lot of sequences simultaneously,you need to create additional threads.
How can I create additional threads without having to modify the Player.cpp class?
#3
You should beware of the forceSet flag,because when you force your sequence,you don't have an information on the backworking sequence, the playback is changing its position runtime T..(0.0-1.0)..T.
Sometimes you hit the transition (250ms) ,sometimes you hit the middle.
You can easy forceSet your sequence,exporting it with the next preority number,but it is a hacky decision.
There is a method,called pickActionAnimation().
There you should handle your sequences.
Creating additional threads (with transition).. you need to move entirely to C++.
06/02/2009 (10:28 am)
Wnen the player is standing,there is also an animation that works("root").You should beware of the forceSet flag,because when you force your sequence,you don't have an information on the backworking sequence, the playback is changing its position runtime T..(0.0-1.0)..T.
Sometimes you hit the transition (250ms) ,sometimes you hit the middle.
You can easy forceSet your sequence,exporting it with the next preority number,but it is a hacky decision.
There is a method,called pickActionAnimation().
There you should handle your sequences.
Creating additional threads (with transition).. you need to move entirely to C++.
#4
> sequence,you don't have an information on the backworking sequence,
> the playback is changing its position runtime T..(0.0-1.0)..T.
> Sometimes you hit the transition (250ms) ,sometimes you hit the middle.
> You can easy forceSet your sequence,exporting it with the next
> preority number,but it is a hacky decision.
Sorry, but I am not very familiar with animations, what's a backworking sequence, how can I always hit the transition? And forceSet should not be used?
> There is a method,called pickActionAnimation().
> There you should handle your sequences.
So, I would have to modify the pickActionAnimation method? All I want to do is play an animation from code (C++ or script), is there no easier way for this? Shouldn't setActionThread actually provide this functionality?
And, of course, thanks for your help with this topic.
06/03/2009 (1:40 am)
> You should beware of the forceSet flag,because when you force your > sequence,you don't have an information on the backworking sequence,
> the playback is changing its position runtime T..(0.0-1.0)..T.
> Sometimes you hit the transition (250ms) ,sometimes you hit the middle.
> You can easy forceSet your sequence,exporting it with the next
> preority number,but it is a hacky decision.
Sorry, but I am not very familiar with animations, what's a backworking sequence, how can I always hit the transition? And forceSet should not be used?
> There is a method,called pickActionAnimation().
> There you should handle your sequences.
So, I would have to modify the pickActionAnimation method? All I want to do is play an animation from code (C++ or script), is there no easier way for this? Shouldn't setActionThread actually provide this functionality?
And, of course, thanks for your help with this topic.
#5
www.garagegames.com/community/forums/viewthread/73223
06/03/2009 (2:41 am)
OK,here is a little animation tutorial:www.garagegames.com/community/forums/viewthread/73223
#6
I don't want to introduce new states like falling or jumping in the player class, I just want to play that animation. Is there no easy way to achieve this?
06/03/2009 (4:01 am)
That looks like a lot effort to realize this, is there no easy way to just play an animation. Maybe I should illustrate my setting: I have an auction where the player should raise his hand when a bid is submitted. The code for that looks as follows:Avatar *bidder = mAvatarMap[message->getBidder()];
bidder->setActionThread("raisehand",false,false,true);I don't want to introduce new states like falling or jumping in the player class, I just want to play that animation. Is there no easy way to achieve this?
#7
in pickActionAnimation() :
06/03/2009 (4:54 am)
Read again post 5 in "Controlling Animations" thread.in pickActionAnimation() :
if (your_condition) action = PlayerData::NewAnim;
#8
06/03/2009 (6:17 am)
Ok, but that's what I wanted to avoid. So, the proper way to do this is to add a new condition to the player class for every animation that I would like to execute? I would now add a condition "raisehand", then would set the condition "raisehand" to true if I want the animation to be played. If I then have another animation e.g. "wavehand" I introduce a new condition and so on. Looks very over complicated to me, but if it's the only way, I'll probably have to do it like this.
#9
Then only advance it and all you need is to control the transition.
Also test this:
06/03/2009 (6:29 am)
If you don't want to create a condition or register an animation,you also can do it manually:S32 YourSeq = shape->findSequence("test_sequence");
mShapeInstance->setSequence(Your_thread,YourSeq,0);Then only advance it and all you need is to control the transition.
Also test this:
%obj.playThread(1, "your_sequence");
#10
When using the %obj.playThread, the animation will get stuck after it has finished playing.
06/04/2009 (3:12 am)
I tried all solutions but none of them have worked so far. When using states in the player.cpp class and when using the setSequence function, the animations just don't get played. I am probably still missing something here.When using the %obj.playThread, the animation will get stuck after it has finished playing.
#11
in C++
in script
It seems to work a bit better, i.e. nearly no animations are "missed", but actually it should essentially be the same as my first version where I directly called it from C++ - maybe it's just a false impression. For now, I'll leave it like this and might dig into the topic again if I have more time.
06/04/2009 (7:54 am)
I had a look at the TGEA demo resource where animations are executed by calling %obj.setActionThread(%seq). It looks like this now in my code:in C++
Avatar *bidder = mAvatarMap[message->getBidder()];
Con::executef("playAnimation",Con::getIntArg(bidder->getId()),"raisehand");in script
function playAnimation(%obj, %anim)
{
%obj.setActionThread(%anim);
}It seems to work a bit better, i.e. nearly no animations are "missed", but actually it should essentially be the same as my first version where I directly called it from C++ - maybe it's just a false impression. For now, I'll leave it like this and might dig into the topic again if I have more time.
#12
07/30/2009 (5:51 am)
Having a similar problem. I have an animation which gets set in certain game states. For instance, the player 'sleeps' so I set %player.setActionThread("sleep");. Once they're done, the player continues to 'wander' around the play area. However, the player is stuck in the 'sleep' animation and doesn't use its forward/run/walk animations.
#13
If you are animating a player, setActionThread should work just fine. I have a game with nearly 40 "emote" animations (wave, sit, sigh) along with various "action" animations (run, jump, root) and they work seemlessly with one another, from script.
The real issue is animating any other kind of object that doesn't have access to setActionThread, and can only invoke playThread. Then you get into all kinds of trouble. But that is content for a different post.
07/30/2009 (6:02 am)
For future readers of this thread, I think it should be noted that it is not a universal truth that all animations be accomplished in C++ as Picasso suggests. This completely undermines the purpose of Torque Script in general and there is no reason ( besides engine bugs ) why one should not be able to accomplish animation tasks from script. If you are animating a player, setActionThread should work just fine. I have a game with nearly 40 "emote" animations (wave, sit, sigh) along with various "action" animations (run, jump, root) and they work seemlessly with one another, from script.
The real issue is animating any other kind of object that doesn't have access to setActionThread, and can only invoke playThread. Then you get into all kinds of trouble. But that is content for a different post.
#14
Jay,
setActionThread will work fine in all cases when the animations are intended to work in a single mActionAnimation.thread .
A lot of the animations are this type of usage:walk,run,damage,sit,crouch,wave,fall,idle...
Most of the users think forceset do not work,because they use it as 4th parameter,but it is supposed to be used as 5th.
People move to C++ when they need an additional functionality.
07/30/2009 (8:13 am)
It is an old thread.Jay,
setActionThread will work fine in all cases when the animations are intended to work in a single mActionAnimation.thread .
A lot of the animations are this type of usage:walk,run,damage,sit,crouch,wave,fall,idle...
Most of the users think forceset do not work,because they use it as 4th parameter,but it is supposed to be used as 5th.
People move to C++ when they need an additional functionality.
Torque Owner Ivan Mandzhukov
Liman3D
That's why it gets stuck when finished.
Playthread is good to use for texture animation over the player.
SetActionThread advances the animation playback in a single thread.
A thread can handle a single sequence.
When you play a second sequence,the main animation thread is already occupied,unless you have a high priority.
If you want to play a lot of sequences simultaneously,you need to create additional threads.
Check for example the arm thread how is done.