Adding Sprint and Swim poses for AI players
by Jeff Yaskus · 03/07/2012 (12:20 am) · 3 comments
This resource adds (2) more poses to the AI Player ... sprint and swim poses.
Steve Acaster did all the hard work previously, over here;
www.garagegames.com/community/resources/view/21164
Now, to update the how -to ... first we don't need to make as many code changes, since some of them are stock now.
*** SOURCE CHANGES ***
Start by making these change in "aiPlayer.cpp";
around line 427, near the end of getAIMove()
and then add this function with changes;
AND at the bottom of AiPlayer.cpp, expose it to script;
Finally, add this near the end of AIPlayer.h;
thats all the engine code changes needed for T3D v1.2 ... now to the Torque Scripts!
*** TORQUE SCRIPT CHANGES ***
Add these updated pose functions to the end of "scripts/server/aiPlayer.cs"
Thats it! The rest is all the same as Steves resource ...
%ID.doStand();
%ID.doCrouch();
%ID.doProne();
%ID.doSprint();
%ID.doSwim();
I've verified its setting the poses, however I haven't gotten the models to actually swim ... possibly it requires them to actual be in water first?!
The doSprint doesn't seem to change the stance ... but if followed by a move command, should take effect.
Finally, I found it defaults back to "stand" if you set it to a mode -- for which there are no animations, such as the prone with the default player object.
Steve Acaster did all the hard work previously, over here;
www.garagegames.com/community/resources/view/21164
Now, to update the how -to ... first we don't need to make as many code changes, since some of them are stock now.
*** SOURCE CHANGES ***
Start by making these change in "aiPlayer.cpp";
around line 427, near the end of getAIMove()
// Replicate the trigger state into the move so that
// triggers can be controlled from scripts.
for( int i = 0; i < MaxTriggerKeys; i++ )
movePtr->trigger[i] = getImageTriggerState(i);
//yorks in start
switch (mPose)
{
case StandPose:
movePtr->trigger[3] = false; // crouch
movePtr->trigger[4] = false; // prone
movePtr->trigger[5] = false; // sprint
break;
case CrouchPose:
movePtr->trigger[3] = true; // crouch
movePtr->trigger[4] = false; // prone
movePtr->trigger[5] = false; // sprint
break;
case PronePose:
movePtr->trigger[3] = false; // crouch
movePtr->trigger[4] = true; // prone
movePtr->trigger[5] = false; // sprint
break;
// JY >>>
case SprintPose:
movePtr->trigger[3] = false; // crouch
movePtr->trigger[4] = false; // prone
movePtr->trigger[5] = true; // sprint
break;
// <<< JY
}
//yorks in endand then add this function with changes;
//yorks - new function!
void AIPlayer::changePose(S32 poseNumber)
{
Pose mPose = StandPose; // default
// JY >>>
switch (poseNumber)
{
case 0: mPose = StandPose; break; // { Player::StandPose, "Stand", "Standard movement pose.n" },
case 1: mPose = SprintPose; break; // { Player::SprintPose, "Sprint", "Sprinting pose.n" },
case 2: mPose = CrouchPose; break; // { Player::CrouchPose, "Crouch", "Crouch pose.n" },
case 3: mPose = PronePose; break; // { Player::PronePose, "Prone", "Prone pose.n" },
case 4: mPose = SwimPose; break; // { Player::SwimPose, "Swim", "Swimming pose.n" },
}
// <<< JY
setPose(mPose);
}
//yorksAND at the bottom of AiPlayer.cpp, expose it to script;
//yorks
ConsoleMethod( AIPlayer, setPose, void, 3, 3, "()"
"(int pose) StandPose=0,SprintPose=1,CrouchPose=2,PronePose=3,SwimPose=4")
{
object->changePose(dAtoi(argv[2]));
}
// yorksFinally, add this near the end of AIPlayer.h;
//... void stopMove(); void changePose(S32 poseNumber); // yorks added }; #endif
thats all the engine code changes needed for T3D v1.2 ... now to the Torque Scripts!
*** TORQUE SCRIPT CHANGES ***
Add these updated pose functions to the end of "scripts/server/aiPlayer.cs"
// Poses ; 0 = stand, 1 = sprint, 2 = crouch, 3 = prone, 4 = swim //
function AiPlayer::doStand(%this)
{
echo(%this.getname() @ " AiStand");
if(%this.getPose() != 0)
{
%this.setPose(0);
%this.schedule(50, "kickStartPose", 0);
}
}
function AiPlayer::doSprint(%this)
{
echo(%this.getname() @ " AiSprint");
if(%this.getPose() != 1)
{
%this.setPose(1);
%this.schedule(50, "kickStartPose", 1);
}
}
function AiPlayer::doCrouch(%this)
{
echo(%this.getname() @ " AiCrouch");
if(%this.getPose() != 2)
{
%this.setPose(2);
%this.schedule(50, "kickStartPose", 2);
}
}
function AiPlayer::doProne(%this)
{
echo(%this.getname() @ " AiProne");
if(%this.getPose() != 3)
{
%this.setPose(3);
%this.schedule(50, "kickStartPose", 3);
}
}
function AiPlayer::doSwim(%this)
{
echo(%this.getname() @ " AiSwim");
if(%this.getPose() != 4)
{
%this.setPose(4);
%this.schedule(50, "kickStartPose", 4);
}
}
//and our kickstart bugfix workaround solution
function AiPlayer::kickStartPose(%this, %pose)
{
echo("kickstart pose " @ %pose);
%this.setPose(%pose);
%this.setTransform(%this.getTransform());
}Thats it! The rest is all the same as Steves resource ...
%ID.doStand();
%ID.doCrouch();
%ID.doProne();
%ID.doSprint();
%ID.doSwim();
I've verified its setting the poses, however I haven't gotten the models to actually swim ... possibly it requires them to actual be in water first?!
The doSprint doesn't seem to change the stance ... but if followed by a move command, should take effect.
Finally, I found it defaults back to "stand" if you set it to a mode -- for which there are no animations, such as the prone with the default player object.
About the author
Long time gamer, hacker and programmer. With dreams of making video games -
#2
06/03/2012 (4:53 pm)
I'm having some trouble getting the AI to stop sprinting. It doesn't look like the doStand() function is doing what it ought to do. It's funny, because giving the AI a doSwim() makes him walk (probably because it doesn't have a swim animation).
#3
10/02/2012 (6:44 am)
Hey Jeff, I'm using UAISK kit and wondering if you could share your wisdom on how to set it up so our ai crouches when fired at or any examples you could help with would be great..... Thanks in advance 
Associate Steve Acaster
[YorkshireRifles.com]