animations only paying after trigger released
by Donald Teal · in Torque 3D Professional · 03/14/2010 (2:44 pm) · 48 replies
I have added some animations to go with the flight code for my player model. I am using T3D1.1a.
in default.bind.cs I have
model goes into flight position but doesn't play the animation untill after the trigger is released.
all animations play fine in model editor.
the flight mechanics work fine and are designed to be enabled only when trigger is pressed. when trigger is
released it goes into fall state.
EDIT: ok it seems that the animation is trying to play but keeps resetting while the 'g' key is down.
what would be a better way to do this so the animation can cycle as long as the key is pressed and not
keep resetting?
in default.bind.cs I have
function glideTrigger(%val)
{
$mvTriggerCount5++;
}
moveMap.bind( keyboard, g, glideTrigger );model goes into flight position but doesn't play the animation untill after the trigger is released.
all animations play fine in model editor.
the flight mechanics work fine and are designed to be enabled only when trigger is pressed. when trigger is
released it goes into fall state.
EDIT: ok it seems that the animation is trying to play but keeps resetting while the 'g' key is down.
what would be a better way to do this so the animation can cycle as long as the key is pressed and not
keep resetting?
About the author
#22
03/21/2010 (11:04 am)
that loses all animations but the idle. seqN only registers 0.
#23
All this is strange,you call your animation,but it does not play.May be the problem is not in the source code.
03/21/2010 (11:50 am)
This method getAction(),are you sure it returns a proper sequence number or returns always 0 ?All this is strange,you call your animation,but it does not play.May be the problem is not in the source code.
#24
then add the glide animations to the model in the editor. everything is handled in the source. thats why I asked if it might be a model issue causing the animation not to play, but it plays after the glide trigger is released so it doesn't make any sense to me.
I could send you the player.cpp and player.h but would prefer not to post entire script on forums. I am at a loss with whats going on.
03/21/2010 (11:57 am)
well in scripts the only calls I have are one in the models datablock canGlide = true and setting the glide trigger in the default.bind.csthen add the glide animations to the model in the editor. everything is handled in the source. thats why I asked if it might be a model issue causing the animation not to play, but it plays after the glide trigger is released so it doesn't make any sense to me.
I could send you the player.cpp and player.h but would prefer not to post entire script on forums. I am at a loss with whats going on.
#25
I also don't see how you read the trigger data (move->trigger[5]) in c++,..may be in updatemove()
I think your best way is to check line by line what happens - if your sequence index is correct and you call directly setactionthread() with wait=true,if nothing happens - then it is a model issue.
Also check your TSShapeConstructor definitions if all sequences are listed there.
03/21/2010 (12:11 pm)
Yes I understand that you can not share the code.I also don't see how you read the trigger data (move->trigger[5]) in c++,..may be in updatemove()
I think your best way is to check line by line what happens - if your sequence index is correct and you call directly setactionthread() with wait=true,if nothing happens - then it is a model issue.
Also check your TSShapeConstructor definitions if all sequences are listed there.
#26
and also
and then
03/21/2010 (2:02 pm)
I have several call in updatemove()// Desired move direction & speed
VectorF moveVec;
F32 moveSpeed;
if (mState == MoveState && mDamageState == Enabled)
{
//------------------------------------Gliding Edit--------------------------------------
// Things need to be handled different when gliding
if(mDataBlock->canGlide && move->trigger[5] && mContactTimer > 10 && mWaterCoverage == 0)
{
zRot.getColumn(1,&moveVec);
}
else
{
more code
}
//--------------------------------------End Edit----------------------------------------
// Clamp water movement
if (move->y > 0.0f)
{
if ( mSwimming )and also
// Cancel any script driven animations if we are going to move.
if (moveVec.x + moveVec.y + moveVec.z != 0.0f &&
(mActionAnimation.action >= PlayerData::NumTableActionAnims
|| mActionAnimation.action == PlayerData::LandAnim))
mActionAnimation.action = PlayerData::NullAnimation;
}
else
{
moveVec.set(0.0f, 0.0f, 0.0f);
moveSpeed = 0.0f;
}
// Acceleration due to gravity
// VectorF acc(0.0f, 0.0f, mGravity * mGravityMod * TickSec);
//------------------------------------Gliding Edit----------------------------------
VectorF acc;
// if(!runSurface)
// {
// if the user is gliding, use the glide specific gravity modifiers
if(mDataBlock->canGlide && move->trigger[5] && mContactTimer > 10 && mWaterCoverage == 0)
{
if(move->y < 0)
{
more code
}
if(move->y == 0)
{
more code
}
if(move->y > 0)
{
more code
}
}
else
{
more code
}
// }
//---------------------------------------End Edit---------------------------------
// Determine ground contact normal. Only look for contacts if
// we can move and aren't mounted.
VectorF contactNormal(0,0,0);
bool jumpSurface = false, runSurface = false;
if ( !isMounted() )also// Clamp acceleration, player also accelerates faster when
// in his hard landing recover state.
F32 maxAcc = (mDataBlock->runForce / getMass()) * TickSec;
if (mState == RecoverState)
maxAcc *= mDataBlock->recoverRunForceScale;
if (runSpeed > maxAcc)
runAcc *= maxAcc / runSpeed;
acc += runAcc;
//----------------------------------Gliding Edit--------------------------------
// If we are running on the ground, then we're not jumping
if (mDataBlock->isJumpAction(mActionAnimation.action))
{
mActionAnimation.action = PlayerData::NullAnimation;
}
// If we are on the ground, we definitely aren't gliding
currentGlideSpeed = 0;
}
if(mContactTimer++)
{
// mContactTimer++;
if(mDataBlock->canGlide && move->trigger[5] && mContactTimer > 10 && mWaterCoverage == 0)
{
// Allow the user to have some control over the glide speed
if(move->y < 0)
{
more code
}
if(move->y == 0)
{
more code
}
if(move->y > 0)
{
more code
}
if(move->x < 0)
{
more code
}
if(move->x == 0)
{
more code
}
if(move->x > 0)
{
more code
}
// If we are gliding, we aren't jumping.
if (mDataBlock->isJumpAction(mActionAnimation.action))
{
mActionAnimation.action = PlayerData::NullAnimation;
}
}
}
//----------------------------------End Edit---------------------------------
else if (!mSwimming && mDataBlock->airControl > 0.0f)
{
VectorF pv;
pv = moveVec;
F32 pvl = pv.len();and then
// Adjust velocity with all the move & gravity acceleration
// TG: I forgot why doesn't the TickSec multiply happen here...
mVelocity += acc;
// apply horizontal air resistance
//-------------------------------------Gliding Edit-----------------------------------
if(mDataBlock->canGlide && !runSurface && move->trigger[5] && mContactTimer > 10 && mWaterCoverage == 0.0)
//---------------------------------------End Edit-------------------------------------
{
F32 hvel = mSqrt(mVelocity.x * mVelocity.x + mVelocity.y * mVelocity.y);
if(hvel > mDataBlock->horizResistSpeed)
#27
one more thing to test:
at the bottom of updateMove(),after all your logic,
call your animation this way:
Now press and hold your button, YourAnim should play.
When the button is released,animation will end.
03/22/2010 (12:13 am)
OK,Donald,one more thing to test:
at the bottom of updateMove(),after all your logic,
call your animation this way:
if(move->trigger[5]) if(mActionAnimation.action != PlayerData::YourAnim) setActionThread(PlayerData::YourAnim, true, false, true,false,true);
Now press and hold your button, YourAnim should play.
When the button is released,animation will end.
#28
03/22/2010 (6:24 am)
ok with that code in and I hit the trigger its plays the animations as long as I am not moving. once I move it stops the animation again. also it plays whether on the ground or in the air. I put this in directly after the // update player pose code at the bottom of the updateMove() method// Update the PlayerPose
Pose desiredPose = mPose;
if ( mSwimming )
desiredPose = SwimPose;
else if ( runSurface && move->trigger[3] && canCrouch() )
desiredPose = CrouchPose;
else if ( runSurface && move->trigger[4] && canProne() )
desiredPose = PronePose;
else if ( canStand() )
desiredPose = StandPose;
setPose( desiredPose );
//////////////////////Gliding Test Edit//////////////////////////
if(move->trigger[5])
if(mActionAnimation.action != PlayerData::glide_idle)
setActionThread(PlayerData::glide_idle, true, false, true,false,true);
///////////////////////End Edit/////////////////////////////
}
#29
When you forceset an animation with the wait flag,it means the rest animations should not play. You say that your run animation plays while holding your key - this is incorrect and now I see the problem is not in your code.
03/22/2010 (7:39 am)
This is not what I expected to hear.When you forceset an animation with the wait flag,it means the rest animations should not play. You say that your run animation plays while holding your key - this is incorrect and now I see the problem is not in your code.
#30
03/22/2010 (8:00 am)
the glide animation plays while the button is pressed but the animation stops when moving. it stays in the glide position but no animation. it doesn't revert to the normal run animation until the button is released.
#31
1. Your trigger is not set as you expect,this can skip the setActionThread() call and your animation will not play.
I think using a Con::printf("I'm in!"); in your inner cycle will show if this is true.
2. Your trigger is fine,but there is an animation issue - may be wrong priorities ?!?
03/22/2010 (8:58 am)
I think there are two possibilities:1. Your trigger is not set as you expect,this can skip the setActionThread() call and your animation will not play.
I think using a Con::printf("I'm in!"); in your inner cycle will show if this is true.
2. Your trigger is fine,but there is an animation issue - may be wrong priorities ?!?
#32
03/22/2010 (9:41 am)
k, I will try that and see what happens. Thanks for helping.
#33
03/23/2010 (2:20 pm)
ok I added in a Con::printf(""); statement in each animation call for the glide. code to follow. with it as it is, model goes into position but animations do not play. getting proper seqN and printf() for each animation although they dont play. no other seqN is called to interupt the glide seq. so does that mean this is a model issue?//-----------------------------gliding edit------------------------
else if(mContactTimer > 10)
//if(mContactTimer > 10)
{
if(currentGlideSpeed != 0)
{
if(currentGlideSpeed == mDataBlock->minGlideSpeed)
{
if(currentBankSpeed < 0)
{
//setActionThread(PlayerData::glide_idle_bank_left, true, false, true,false,true);
action = PlayerData::glide_idle_bank_left;
//action = getAction("glide_idle_bank_left");
Con::printf("glide_idle_bank_left");
}
else if(currentBankSpeed == 0)
{
//setActionThread(PlayerData::glide_idle, true, false, true,false,true);
action = PlayerData::glide_idle;
//action = getAction("glide_idle");
Con::printf("glide_idle");
}
else if(currentBankSpeed > 0)
{
//setActionThread(PlayerData::glide_idle_bank_right, true, false, true,false,true);
action = PlayerData::glide_idle_bank_right;
//action = getAction("glide_idle_bank_right");
Con::printf("glide_idle_bank_right");
}
}
else if(currentGlideSpeed == mDataBlock->midGlideSpeed)
{
if(currentBankSpeed < 0)
{
//setActionThread(PlayerData::glide_walk_bank_left, true, false, true,false,true);
action = PlayerData::glide_walk_bank_left;
//action = getAction("glide_walk_bank_left");
Con::printf("glide_walk_bank_left");
}
else if(currentBankSpeed == 0)
{
//setActionThread(PlayerData::glide_walk, true, false, true,false,true);
action = PlayerData::glide_walk;
//action = getAction("glide_walk");
Con::printf("glide_walk");
}
else if(currentBankSpeed > 0)
{
//setActionThread(PlayerData::glide_walk_bank_right, true, false, true,false,true);
action = PlayerData::glide_walk_bank_right;
//action = getAction("glide_walk_bank_right");
Con::printf("glide_walk_bank_right");
}
}
else if(currentGlideSpeed == mDataBlock->maxGlideSpeed)
{
if(currentBankSpeed < 0)
{
//setActionThread(PlayerData::glide_run_bank_left, true, false, true,false,true);
action = PlayerData::glide_run_bank_left;
//action = getAction("glide_run_bank_left");
Con::printf("glide_run_bank_left");
}
else if(currentBankSpeed == 0)
{
//setActionThread(PlayerData::glide_run, true, false, true,false,true);
action = PlayerData::glide_run;
//action = getAction("glide_run");
Con::printf("glide_run");
}
else if(currentBankSpeed > 0)
{
//setActionThread(PlayerData::glide_run_bank_right, true, false, true,false,true);
action = PlayerData::glide_run_bank_right;
//action = getAction("glide_run_bank_right");
Con::printf("glide_run_bank_right");
}
}
}
else
{
if (mContactTimer >= sContactTickTime)
{
// Nothing under our feet
action = PlayerData::RootAnim;
}
}
}
//--------------------------------End Edit---------------------------
#34
Sounds like a model issue.
03/24/2010 (12:10 am)
You get a sequence number,you see the printf in console,but no animation.Sounds like a model issue.
#35
03/24/2010 (7:38 am)
ok thanks for all the help. I think I still have a little hair left. Now to throw it back to the artist. I have atleast learned from this so its not a total loss. thanks again
#36
c:\torque\flight_gmk_uaisk\engine\source\core\util\tvector.h(658) : Fatal - Vector<T>::operator[] - out of bounds array access!
code crashing is
03/26/2010 (4:24 pm)
well there must still be something going on in the code. I am getting an error when running in debug that crashes the game on load.c:\torque\flight_gmk_uaisk\engine\source\core\util\tvector.h(658) : Fatal - Vector<T>::operator[] - out of bounds array access!
code crashing is
template<class T> inline T& Vector<T>::operator[](U32 index)
{
AssertFatal(index < mElementCount, "Vector<T>::operator[] - out of bounds array access!");
return mArray[index];
}
#37
03/27/2010 (12:06 am)
While debugging press shift+F11 to step out a few times,this will show where the problem is.
#38
but here are the 2 erors I get. one I get repeatedly.
tools/worldEditor/scripts/EditorGui.ed.cs (1221): string always evaluates to 0.
core/scripts/server/commands.cs (152): Unable to find object: '' attempting to call function 'setValidEditOrbitPoint' <-----------repeated error line 152
and this is the final lines of the console.txt
*** Phase 3: Mission Lighting
Mission lighting done
Mapping string: MissionStartPhase3Ack to index: 2
Mapping string: MissionStart to index: 11
Mapping string: SyncClock to index: 12
Mapping string: RefreshWeaponHud to index: 13
Mapping string: updateGameScore to index: 14
Mapping string: enableReticle to index: 15
03/27/2010 (9:24 am)
crashes before the game loadsbut here are the 2 erors I get. one I get repeatedly.
tools/worldEditor/scripts/EditorGui.ed.cs (1221): string always evaluates to 0.
core/scripts/server/commands.cs (152): Unable to find object: '' attempting to call function 'setValidEditOrbitPoint' <-----------repeated error line 152
and this is the final lines of the console.txt
*** Phase 3: Mission Lighting
Mission lighting done
Mapping string: MissionStartPhase3Ack to index: 2
Mapping string: MissionStart to index: 11
Mapping string: SyncClock to index: 12
Mapping string: RefreshWeaponHud to index: 13
Mapping string: updateGameScore to index: 14
Mapping string: enableReticle to index: 15
#39
This has nothing to do with your trigger code,this is a separate problem.
You have to analyze and find the reason for this.
03/27/2010 (10:02 am)
hmm,this seems to be a bug.This has nothing to do with your trigger code,this is a separate problem.
You have to analyze and find the reason for this.
#40
03/27/2010 (10:05 am)
ok well if its a bug should I go to T3D1.1b and see if it happens there as well. then if it does trace it down and bug report it but if its gone then it should have been fixed already
Torque Owner Ivan Mandzhukov
Liman3D
// Our feet are on something // Pick animation that is the best fit for our current velocity. // Assumes that root is the first animation in the list. F32 curMax = 0.1f; VectorF vel; mWorldToObj.mulV(mVelocity,&vel); for (U32 i = 1; i < PlayerData::NumMoveActionAnims; i++) { PlayerData::ActionAnimation &anim = mDataBlock->actionList[i]; if (anim.sequence != -1 && anim.speed) { // We bias towards picking the forward/backward anims over // the side to prevent oscillation between anims. This seems // to work ok but the real fix is to have 8 way directional // animations. VectorF biasedDir = anim.dir * VectorF(0.5f,1.0f,0.5f); F32 d = mDot(vel, biasedDir); if (d > curMax) { curMax = d; action = i;//this one sets run animation forward = true; }This is the code that sets the run animation.
Try to put (action = i;) in a comment.
Now the run sequence will not be set.