Game Development Community

stopping animation at any frame

by PGames · in Torque 3D Professional · 08/09/2010 (2:01 am) · 2 replies

Is there a way to get the real time frame of an animation and the stop the animation? Basically, I want to play an animation, say a walk, then stop said animation the moment I press a key and have it blend directly into the next animation. To do this, I need to know the exact frame reference of the walk animation when I press the key and be able to stop it.

I'm using this right now to try to stop the animation in player.cpp:

void Player::stopPlayOnce()
{
	mShapeInstance->setTimeScale(mArmAnimation.thread,0.0);

	// only do this if on server
	if (!isGhost())
		setArmThread(mArmThreadSavedAction);
}

But, it doesn't work, anyone know what's wrong?

Also, the blending between animations in the object editor looks really good, does anyone know where the code for that is? I would like to use that to create the inbetween animations (say from running to attack stance).

#1
08/09/2010 (10:47 pm)
You can use the normal 'transitionToSequence' method for this. It will stop the sequence playing in the thread, and transition to a new one, optionally playing the new sequence during the blend period. eg.

F32 currentPos = mShapeInstance->getPos( mArmAnimation.thread );
S32 nextSeq = mShapeInstance->getShape()->findSequence( "nextSequence");
F32 blendDuration = 0.5f;  // blend over 0.5 seconds
bool playNextSeqDuringBlend = true;

mShapeInstance->transitionToSequence( mArmAnimation.thread, nextSeq, currentPos, blendDuration, playNextSeqDuringBlend );

Quote:Also, the blending between animations in the object editor looks really good, does anyone know where the code for that is?

The Shape Editor code is in gui/editor/guiShapeEdPreview.cpp. It uses the standard TSShapeInstance methods for animation.
#2
08/11/2010 (1:35 pm)
Yep, that works, thank you!