Override the Engine to use setActionThread
by Katrina Rose · in Torque Game Engine · 11/05/2004 (6:18 am) · 17 replies
Hi,
I have heard a few people on these forums talking about the engine over riding the setActionThread if you use it on a moving player, and I too have experienced this. We have bots that I currently have walking by changing the run animation to a walk animation and then telling the engine that is is the run animation. I then adjusted the setMoveSpeed to a number that has the bots walking. What I want to do is have the bots walking around there paths and when they see you change to a run. If they lose sight of you I want them to go back to walking. I have all the coding in the cs files done, but if I change the setActionThread for the bot to a run animation it will play it for a split second and then continue to play the walk animarion. What code in the engine do I need to change to make the setActionThread over ride the enigne code? Thanks in advance for any help you can provide.
Marrion
I have heard a few people on these forums talking about the engine over riding the setActionThread if you use it on a moving player, and I too have experienced this. We have bots that I currently have walking by changing the run animation to a walk animation and then telling the engine that is is the run animation. I then adjusted the setMoveSpeed to a number that has the bots walking. What I want to do is have the bots walking around there paths and when they see you change to a run. If they lose sight of you I want them to go back to walking. I have all the coding in the cs files done, but if I change the setActionThread for the bot to a run animation it will play it for a split second and then continue to play the walk animarion. What code in the engine do I need to change to make the setActionThread over ride the enigne code? Thanks in advance for any help you can provide.
Marrion
About the author
#2
But this will not work. If you use the same animation for walk and run it will not look right. I need to be able to change the animation depending on what I want him to do. One other reason to change the animation is that I would like to also have the bots able to duck and mabie roll. If I don't over ride the C++ stuff I can't do any of that.
Thanks for your help,
Marrion
11/08/2004 (3:21 am)
Thanks Erik,But this will not work. If you use the same animation for walk and run it will not look right. I need to be able to change the animation depending on what I want him to do. One other reason to change the animation is that I would like to also have the bots able to duck and mabie roll. If I don't over ride the C++ stuff I can't do any of that.
Thanks for your help,
Marrion
#3
11/08/2004 (9:36 am)
I think Erik is saying that the C++ code already does the walk/run behavior you want...
#4
Marrion
11/08/2004 (9:42 am)
It will allow me to change the speed to walk, but not the animation. I looked through all the code in player.cc, and there is no animation for walk in there. I can add a walk animation, but it is being overridden by the run code in player.cc. As the code stands right now I can either have a walk animation or run animation, but not both. I need to know how to keep the engine from doing things in auto mode.Marrion
#5
My point is, the code to determine when/how to change is there.
11/08/2004 (10:33 am)
Adding a seperate animation would be quite easy, Ive added 6-10 action anims myself.My point is, the code to determine when/how to change is there.
#6
What do I need to change in the code to add more animations? I apreciate your help.
Marrion
11/08/2004 (12:22 pm)
Hi Erik,What do I need to change in the code to add more animations? I apreciate your help.
Marrion
#7
11/08/2004 (3:20 pm)
Use this resource as a starting point. Just pick and choose whatever parts of the code suit your use.
#8
I have used the player.h and player.cc stuff in the swimming resource, but somewhere in the code it's over riding what I do. No matter how I do it I can't get the walk animation to play instead of the run animation. If the Vel.y < 0.5 && Vel.y > 0.1 then I have action = PlayerData::WalkForwardAnimation. Then run animation plays for all movements forward no matter what I do. What am I doing wrong? This is what I have:
player.h
What am I doing wrong? Thanks for your help
Marrion
11/09/2004 (9:36 am)
Hi Erik,I have used the player.h and player.cc stuff in the swimming resource, but somewhere in the code it's over riding what I do. No matter how I do it I can't get the walk animation to play instead of the run animation. If the Vel.y < 0.5 && Vel.y > 0.1 then I have action = PlayerData::WalkForwardAnimation. Then run animation plays for all movements forward no matter what I do. What am I doing wrong? This is what I have:
player.h
RootAnim,
RunForwardAnim,
BackBackwardAnim,
SideLeftAnim,
WalkForwardAnim,
// These are set explicitly based on player actions
FallAnim,
JumpAnim,
StandJumpAnim,
LandAnim,player.cc in pickActionAnimation()VectorF vel; mWorldToObj.mulV(mVelocity,&vel); if (vel.y < 0.5) action = PlayerData::walkForwardAnim; setActionThread(action,forward,false,false);in the Villan.cs File I have
datablock TSShapeConstructor(VillanDts)
{
baseShape = "./villan.dts";
sequence0 = "./villan_root.dsq root";
sequence1 = "./villan_run.dsq run";
sequence2 = "./villan_death1.dsq death1";
sequence3 = "./villan_scout.dsq scout";
sequence4 = "./villan_walk.dsq walk";
sequence5 = "./villan_death2.dsq death2";
sequence6 = "./villan_death3.dsq death3";
};What am I doing wrong? Thanks for your help
Marrion
#9
Have you verified your walk animation? Try also changing the code to use _only_ the walk animation.
Otherwise, I'll get in deep with that code in a day or two and see if I can't find your problem.
11/09/2004 (2:06 pm)
Offhand, I don't see any problem. Perhaps your total velocity is too high? Try echoing all 3 velocity readings every time you switch animations. It will probably spam the crap out of your log, so only run it for a moment.Have you verified your walk animation? Try also changing the code to use _only_ the walk animation.
Otherwise, I'll get in deep with that code in a day or two and see if I can't find your problem.
#10
Thanks for your help though.
11/10/2004 (3:02 am)
If the character is stopped it plays the run animation because the Vel.y returns 0. In the C++ code I can't seem to get the walk animation to play at all no matter what I try.If I change run to walk in the villan.cs file the walk file plays fine, but the run won't play. I don't understand what I am doing wrong.Thanks for your help though.
#11
Thanks in Advance.
Marrion
11/10/2004 (9:44 am)
One thing I now know for sure is that the AIPlayer class does not use the Player.pickActionAnimation(). If I hard code the animation to the walk; the only character in the game that does the walk is the player. The AIPlayer still runs everywhere. Does anyone know where I can set the AIPlayer animations?Thanks in Advance.
Marrion
#12
AIplayer does use all the players move code, but certain aspects are overridden first in updateAIMove(). I'm not sure why they wouldn't switch to the walk animation when you hardcode that as the only choice. Are the mobs using their own animation data, or sharing the players?
I never got around to adding seperate animations for walk/run myself, planning to do it another day. But, your problem has me intrigued, and I do have those animations ready to go, so I'm going to be adding it myself in the next day or so. All my other action animations work great, including crouching and crawling. The problem can't be anything major.
11/10/2004 (10:16 am)
Still looking for original problem....AIplayer does use all the players move code, but certain aspects are overridden first in updateAIMove(). I'm not sure why they wouldn't switch to the walk animation when you hardcode that as the only choice. Are the mobs using their own animation data, or sharing the players?
I never got around to adding seperate animations for walk/run myself, planning to do it another day. But, your problem has me intrigued, and I do have those animations ready to go, so I'm going to be adding it myself in the next day or so. All my other action animations work great, including crouching and crawling. The problem can't be anything major.
#13
Marrion
11/10/2004 (10:23 am)
I am using a different animation than the player. My Villan players have all there own animations. This is killing me. It seems so simple to just determine there speed and then play the appropriate animation based on that speed. Nothing I try will change the animation for the AIPlayers. Somewhere in the Player or AIPlayer code I am being overridden, but it's not using animation name calls (RunForwardAnimation). It must be using the sequence number, but I can't figure out how to override it. Thanks again for your help.Marrion
#14
I just tried this also, and the AIPlayers do not change there animation, but the player animation changes.
Thanks for your help,
Marrion
11/15/2004 (5:51 am)
Hi Erik,I just tried this also, and the AIPlayers do not change there animation, but the player animation changes.
void Player::setActionThread(U32 action,bool forward,bool hold,bool wait,bool fsp, bool forceSet)
{
if (mActionAnimation.action == action && !forceSet)
return;
if (action >= PlayerData::NumActionAnims)
{
Con::errorf("Player::setActionThread(%d): Player action out of range", action);
return;
}
[b]
//PlayerData::ActionAnimation &anim = mDataBlock->actionList[action]; FROM
PlayerData::ActionAnimation &anim = mDataBlock->actionList[4]; //TO
[/b]
if (anim.sequence != -1)
{
mActionAnimation.action = action;
mActionAnimation.forward = forward;
mActionAnimation.firstPerson = fsp;
mActionAnimation.holdAtEnd = hold;
mActionAnimation.waitForEnd = hold? true: wait;
mActionAnimation.animateOnServer = fsp;
mActionAnimation.atEnd = false;
mActionAnimation.delayTicks = (S32)sNewAnimationTickTime;
mActionAnimation.atEnd = false;
if (sUseAnimationTransitions && (isGhost()/* || mActionAnimation.animateOnServer*/))
{
// The transition code needs the timeScale to be set in the
// right direction to know which way to go.
F32 transTime = sAnimationTransitionTime;
if (mDataBlock && mDataBlock->isJumpAction(action))
transTime = 0.15;
mShapeInstance->setTimeScale(mActionAnimation.thread,
mActionAnimation.forward? 1: -1);
mShapeInstance->transitionToSequence(mActionAnimation.thread,anim.sequence,
mActionAnimation.forward? 0: 1, transTime, true);
}
else
mShapeInstance->setSequence(mActionAnimation.thread,anim.sequence,
mActionAnimation.forward? 0: 1);
}
}In ActionThread 4 is the sequence number for my walk animation. The AIPlayers still play the RUN animation, but my player plays the walk animation. I can't figure out where the AIPlayers are getting there run animation from.Thanks for your help,
Marrion
#15
So did anyone manage to do this?
08/31/2006 (1:36 am)
Hi, i am reading up on how to enable aiplayer to do run animation and walk animation. So did anyone manage to do this?
#16
just define a varaible like bool mWalk and set it true in a function like player::doWalk()
and call the doWalk function in a consolemethod of player ,
this will work , i'm using this way !
12/07/2007 (6:39 am)
Yes,just define a varaible like bool mWalk and set it true in a function like player::doWalk()
and call the doWalk function in a consolemethod of player ,
this will work , i'm using this way !
#17
12/07/2007 (9:52 pm)
Aside from the fact that this is a dead thread from over a year ago.. I'm not sure that there was ever anything wrong. The OP set his walk threshold to 0.5, which is about 1 mph. I'd guess the reason he never saw the animation had to do with the fact that either nothing actually moves that slowly or AIPlayer objects don't have correct velocities set in some situations. I have a setup similar to his for crouch and prone movement which works fine for AIPlayer objects.
Torque Owner Erik Madison
Code currently chooses walk or run based on your speed, therefore that is all you need to adjust in script. Give your players/bots/whomever a variable speed with this resource, then simply adjust their speed in script. The code will handle the rest.