Calling animations from script and from code
by University of Central FL (#0003) · in Torque Game Engine · 06/16/2006 (3:18 pm) · 11 replies
I have a blob character that has the ability to float. After you jump, if you press and hold jump again he starts floating, and I call a cyclic float animation from script, and it works fine. This is the code I'm using, after setting up the new animations in player.cc and player.h and linking them in player.cs:
I want the animation to stop when the blob hits the ground, which in my experience can only be done in engine code. Finding if the player is currently on the ground is done with the following code:
Now, I want the blob to stop playing his float animation when he hits the ground, and I'm not too sure how to do this. I do change some values in my datablock (I know I'm not supposed to do this), but the game is single player, so it works. I tried the following code...
...but the animations go kinda crazy. Anyone know how I can stop the float animation when I hit the ground and go right back into the idle (if I'm standing still) or the normal move animation (if I'm moving)?
(these animations are handled automatically by the engine, but it seems my setActionThread never really stops the float animation, and it keeps trying to do it while the character walks around. It looks strange ).
Anyone have experience with starting/stopping animations from engine code?
$player.playThread( 2 , "floatIdle" );
I want the animation to stop when the blob hits the ground, which in my experience can only be done in engine code. Finding if the player is currently on the ground is done with the following code:
VectorF contactNormal;
bool jumpSurface = false, runSurface = false;
if (!isMounted())
findContact(&runSurface,&jumpSurface,&contactNormal);
if (jumpSurface)
mJumpSurfaceNormal = contactNormal;
if( runSurface )
{
// blob is on the ground
...
}Now, I want the blob to stop playing his float animation when he hits the ground, and I'm not too sure how to do this. I do change some values in my datablock (I know I'm not supposed to do this), but the game is single player, so it works. I tried the following code...
if( runSurface )
{
mDataBlock->isBlobOnGround = true;
if( mDataBlock->isBlobFloating )
{
// reset the floating and the drag
mDataBlock->isBlobFloating = false;
mDataBlock->drag = 0.25;
mDataBlock->airControl = 0.0;
mDataBlock->runForce = 1600;
// cancel any script animations when we hit the ground
mActionAnimation.action = PlayerData::NullAnimation;
setActionThread(PlayerData::RootAnim,true,false,false);
......but the animations go kinda crazy. Anyone know how I can stop the float animation when I hit the ground and go right back into the idle (if I'm standing still) or the normal move animation (if I'm moving)?
(these animations are handled automatically by the engine, but it seems my setActionThread never really stops the float animation, and it keeps trying to do it while the character walks around. It looks strange ).
Anyone have experience with starting/stopping animations from engine code?
#2
The customAirAnimation variable is something I'm using, but the method you use to determine what animations to play is wholly up to you. I just found this the best place to be setting animations while in the air for my needs, not sure if it'll work for you.
06/18/2006 (9:30 pm)
I by no means endorse this as a proper method, but for all the animations I needed to be played while in the air, I put some code in hereelse
if (jumpSurface) {
if (mJumpDelay > 0)
mJumpDelay--;
mJumpSurfaceLastContact = 0;
}
else{
mJumpSurfaceLastContact++;
[i]//Stuff I added in italics
if(mCustomAirAnimation == 1)
setActionThread(PlayerData::OtherAirAnimation, true, false, true)
else
[/i]
setActionThread(PlayerData::StandJumpAnim, false, false, true);The customAirAnimation variable is something I'm using, but the method you use to determine what animations to play is wholly up to you. I just found this the best place to be setting animations while in the air for my needs, not sure if it'll work for you.
#3
I kinda got fed up with calling animations from engine code, so when the player hits the ground, if he's currently floating I use Con::executef to call a script function that should be able to stop the "float" thread that's playing.
I know the executef is working because I echo to the console, but the stopThread doesn't seem to be working correctly. I even tried scheduling the stop, and it still didn't work.
I'm at my wit's end here. Animations in torque are so screwed up. Three semesters ago we used an engine called Panda3d which in no way is as advanced as torque, but calling animations in that engine was infinitely easier.
Anyone know why calling $player.stopThread( 2 ), or $player.schedule( 100, stopThread, 2 ) would NOT stop a cyclic float animation from playing when the animation is playing on thread # 2?
Also, why on earth does this code exist: (player.cc, around line 1579)
Cancel script animations if we are going to move? Does this mean I can't call any script animations while moving?
06/18/2006 (9:38 pm)
I appreciate that Paul, but that's only part of my problem. My other problem is stopping the float animation when the player hits the ground again.I kinda got fed up with calling animations from engine code, so when the player hits the ground, if he's currently floating I use Con::executef to call a script function that should be able to stop the "float" thread that's playing.
I know the executef is working because I echo to the console, but the stopThread doesn't seem to be working correctly. I even tried scheduling the stop, and it still didn't work.
I'm at my wit's end here. Animations in torque are so screwed up. Three semesters ago we used an engine called Panda3d which in no way is as advanced as torque, but calling animations in that engine was infinitely easier.
Anyone know why calling $player.stopThread( 2 ), or $player.schedule( 100, stopThread, 2 ) would NOT stop a cyclic float animation from playing when the animation is playing on thread # 2?
Also, why on earth does this code exist: (player.cc, around line 1579)
// Cancel any script driven animations if we are going to move.
if (moveVec.x + moveVec.y + moveVec.z != 0 &&
(mActionAnimation.action >= PlayerData::NumTableActionAnims
|| mActionAnimation.action == PlayerData::LandAnim))
mActionAnimation.action = PlayerData::NullAnimation;Cancel script animations if we are going to move? Does this mean I can't call any script animations while moving?
#4
06/19/2006 (2:15 am)
Yes well, from what I've seen, that place I am setting the animations in source makes it so they only play in the air, and the rest of the stock code takes over for normal movement animations when you're on the ground.
#5
06/19/2006 (4:11 am)
What Paul said should work, I did the same.
#6
- Custom jump animation (which works fine)
- Custom fall animation (cyclic, after a jump, in the air only)
- Float animation (cyclic, user activated, can happen any time in the air)
The player can float any time in the air, at which time the blob should change his animation to the float and cycle through it until the spacebar is let go.
My problem is when the player hits the ground, the float should stop playing, but it doesn't really. It freaks out and sorta half plays, with the walk cycle overriding it every so often. I start the float animation in SCRIPT, not in code.
I was looking for a reliable way to stop script animations from code. Animations with this engine are absolutely rediculous.
06/19/2006 (8:15 am)
Ok maybe I'm not being clear. Here's what I have:- Custom jump animation (which works fine)
- Custom fall animation (cyclic, after a jump, in the air only)
- Float animation (cyclic, user activated, can happen any time in the air)
The player can float any time in the air, at which time the blob should change his animation to the float and cycle through it until the spacebar is let go.
My problem is when the player hits the ground, the float should stop playing, but it doesn't really. It freaks out and sorta half plays, with the walk cycle overriding it every so often. I start the float animation in SCRIPT, not in code.
I was looking for a reliable way to stop script animations from code. Animations with this engine are absolutely rediculous.
#7
- Custom jump animation (which works fine)
- Custom fall animation (cyclic, after a jump, in the air only)
- Float animation (cyclic, user activated, can happen any time in the air)
The player can float any time in the air, at which time the blob should change his animation to the float and cycle through it until the spacebar is let go.
My problem is when the player hits the ground, the float should stop playing, but it doesn't really. It freaks out and sorta half plays, with the walk cycle overriding it every so often. I start the float animation in SCRIPT, not in code.
I was looking for a reliable way to stop script animations from code. Animations with this engine are absolutely rediculous.
06/19/2006 (8:41 am)
Ok maybe I'm not being clear. Here's what I have:- Custom jump animation (which works fine)
- Custom fall animation (cyclic, after a jump, in the air only)
- Float animation (cyclic, user activated, can happen any time in the air)
The player can float any time in the air, at which time the blob should change his animation to the float and cycle through it until the spacebar is let go.
My problem is when the player hits the ground, the float should stop playing, but it doesn't really. It freaks out and sorta half plays, with the walk cycle overriding it every so often. I start the float animation in SCRIPT, not in code.
I was looking for a reliable way to stop script animations from code. Animations with this engine are absolutely rediculous.
#8
- Custom jump animation (which works fine)
- Custom fall animation (cyclic, after a jump, in the air only)
- Float animation (cyclic, user activated, can happen any time in the air)
The player can float any time in the air, at which time the blob should change his animation to the float and cycle through it until the spacebar is let go.
My problem is when the player hits the ground, the float should stop playing, but it doesn't really. It freaks out and sorta half plays, with the walk cycle overriding it every so often. I start the float animation in SCRIPT, not in code.
I was looking for a reliable way to stop script animations from code. Animations with this engine are absolutely rediculous.
06/19/2006 (11:14 am)
Ok maybe I'm not being clear. Here's what I have:- Custom jump animation (which works fine)
- Custom fall animation (cyclic, after a jump, in the air only)
- Float animation (cyclic, user activated, can happen any time in the air)
The player can float any time in the air, at which time the blob should change his animation to the float and cycle through it until the spacebar is let go.
My problem is when the player hits the ground, the float should stop playing, but it doesn't really. It freaks out and sorta half plays, with the walk cycle overriding it every so often. I start the float animation in SCRIPT, not in code.
I was looking for a reliable way to stop script animations from code. Animations with this engine are absolutely rediculous.
#9
06/19/2006 (11:15 am)
Also, I tried your code. It works except the jump animation loops forever whenever I jump. How do I get it to not loop? The jump animation was definitely exported as non-cyclic, so I'm not sure what the problem is.
#10
06/19/2006 (12:56 pm)
I'm not sure either, I exported non-cyclic animations and had them run fine being played there. Maybe check the bool parameters being passed into setActionThread?
#11
For your specific description, you basically want to examine the playing of the "falling" animation in detail, understand how it is applied, and then modify for your needs. Script calls aren't the way to go here, since pickActionAnimation is called every processTick(), and will automatically over-ride script based animation selection.
06/19/2006 (1:18 pm)
Animations for the Player object class in Torque are designed so that the engine handles input and physics based modification to the 3 animation threads that are playing concurrently. To over-ride/modify this behaviour, you want to fully understand how Player::pickActionAnimation() is operating, and add in your specific procedural animation sequencing.For your specific description, you basically want to examine the playing of the "falling" animation in detail, understand how it is applied, and then modify for your needs. Script calls aren't the way to go here, since pickActionAnimation is called every processTick(), and will automatically over-ride script based animation selection.
Torque Owner University of Central FL (#0003)