Getting the current frame of an animation
by Dean · in Torque Game Engine · 06/15/2007 (9:20 pm) · 6 replies
I've learned how to create an animation and add it into my game with script and code. and I know how to execute said animations, but I can't seem to figure out what commands to use to get the current frame of an animation or find out if an animation is complete. I've tried mActionAnimation.atEnd but it doesn't seem to work like I had hoped. So for example if i want to throw a punch, i want the damage to be applied at a certain frame, and then at the end frame he can either go back to his fighting stance or execute a combo. All I need to figure out in order to do this is how to get the current frame of the animation so I can trigger damage or another animation.
#2
06/16/2007 (1:56 pm)
The only possibility I know of is a mod Eric Hartman did for his game where he hacked up the IFL animation and added a new console method like "setThreadPos" which I assume comes with "getThreadPos". I think i'll leave that one to you to wrestle out of him haha.
#3
i believe there's a way to mark certain frames in the animation so that they trigger callbacks in the engine.
you mark the frames in your animation-creation tool ie, 3DSMax.
ie, instead of manually checking what frame number it's at, you just get a callback at the right time.
the bad news is i've never actually used these guys and don't know where specifically to point you,
but some searching along those lines might turn it up.
heh, it's sort of like getting Rumors from the old Innkeeper in Bard's Tale or something..
yay!
06/16/2007 (3:39 pm)
Dean - presuming you're talking about skeleton DSQ animations here,i believe there's a way to mark certain frames in the animation so that they trigger callbacks in the engine.
you mark the frames in your animation-creation tool ie, 3DSMax.
ie, instead of manually checking what frame number it's at, you just get a callback at the right time.
the bad news is i've never actually used these guys and don't know where specifically to point you,
but some searching along those lines might turn it up.
heh, it's sort of like getting Rumors from the old Innkeeper in Bard's Tale or something..
yay!
#4
I'm not sure you can get the current frame of an animation without modifying the engine code, and even that would be difficult, I think.
You can, however, find out if an animation is complete, since the engine has that already built-in. I work primarily from script, so here is how you would do it on the script side:
If the object you are animating is a Player or aiPlayer object, then the engine executes a script callback whenever an animation sequence called via setActionThread() is done -- called "animationDone". So you just need a Player::animationDone() method in script.
Player, aiPlayer, and other objects animated using playThread() get a script callback called "onEndSequence" when the animation is done, so you would just need one of those for your object in script.
Animation triggers can be set in your animation program, like 3dsMax. One way to use these to trigger sounds is shown in this resource.
Edit: corrected the callback name.
06/16/2007 (3:45 pm)
Orion is correct...I'm not sure you can get the current frame of an animation without modifying the engine code, and even that would be difficult, I think.
You can, however, find out if an animation is complete, since the engine has that already built-in. I work primarily from script, so here is how you would do it on the script side:
If the object you are animating is a Player or aiPlayer object, then the engine executes a script callback whenever an animation sequence called via setActionThread() is done -- called "animationDone". So you just need a Player::animationDone() method in script.
Player, aiPlayer, and other objects animated using playThread() get a script callback called "onEndSequence" when the animation is done, so you would just need one of those for your object in script.
Animation triggers can be set in your animation program, like 3dsMax. One way to use these to trigger sounds is shown in this resource.
Edit: corrected the callback name.
#5
btw i'm not using collision detection for combat in my game. its strictly, if the character is close enough to hit, the impact hits on the right frame.
06/17/2007 (7:17 pm)
Ah. that helps. I was having some success in code with mShapeInstance->getKeyframeNumber(mActionAnimation.thread) . But that opened up a whole other can of worms like the masks wouldnt dirty when i told them to and values kept reverting themselves so I'll try doing it in script and save myself some trouble.btw i'm not using collision detection for combat in my game. its strictly, if the character is close enough to hit, the impact hits on the right frame.
#6
... but it's not working. I currently have a punch animation (non cyclic) and i push j to execute the punch. he punches... but no echo. At least I'm getting closer to the answer (hopefully)
here's the line where it sends "animationDone"
I'm not sure why my animation doesn't "qualify". does the animation need some sort of requirement before it'll send ? It looks like it only does it if the player is in a certain animation. Does your animation have to return to the root position or something? In the code, i can manually send animation done by removing the if, and my script functions work.
06/17/2007 (11:20 pm)
I tried something from another thread, adding this to server/scripts/player.cs function Player::animationDone(%this,%obj)
{
// Inform the client
if (isObject(%obj.client.player))
{
echo("Player::animationDone");
}
}i also tried it with function Player::onEndSequence(%this,%obj,%slot)... but it's not working. I currently have a punch animation (non cyclic) and i push j to execute the punch. he punches... but no echo. At least I'm getting closer to the answer (hopefully)
here's the line where it sends "animationDone"
if ( isServerObject() && mActionAnimation.action >=PlayerData::NumTableActionAnims )
Con::executef(mDataBlock,3,"animationDone",scriptThis());I'm not sure why my animation doesn't "qualify". does the animation need some sort of requirement before it'll send ? It looks like it only does it if the player is in a certain animation. Does your animation have to return to the root position or something? In the code, i can manually send animation done by removing the if, and my script functions work.
Torque Owner Brown Student (#0123)