Game Development Community

Ai Crouches But Does Not Animate - FIXED

by Steve Acaster · in Torque 3D Professional · 11/29/2013 (2:47 pm) · 4 replies

Many moons ago I managed to add crouching/poses to the Ai ... with the one problem that they always had to be forced to play the animation.

They changed their boundsbox and went into crouch pose quite happily ... but the animation would never update with the change (without a hideous hack).

www.yorkshirerifles.com/random/crouchbounds.jpg

Anyhow ... I've been debugging again and still can't seem to spot why it fails.

==>bob.setaipose(1);
canCrouch - crouching allowed //go crouch
canCrouch Has crouch animation
canCrouch is not already crouching
updateMove crouch desiredPose
updateActionThread
pickActionAnimation Ai Crouch //<---- hurray!
setActionThread2
setActionThread2 End 
updateActionThread end action = 10 //<---crouch
pickActionAnimation Ai Stand //<----UwotM8!?
setActionThread2
updateActionThread end action = 0 //<---standing root :(
canCrouch - crouching allowed //go crouch
canCrouch Has crouch animation
canCrouch is already crouching - return true //we are crouching ... but the animation isn't
updateMove crouch desiredPose 
updateActionThread end action = 10 //<---crouch
canCrouch - crouching allowed //go crouch --- and LOOP
canCrouch Has crouch animation
canCrouch is already crouching - return true //we are crouching ... but the animation isn't
updateMove crouch desiredPose
updateActionThread end action = 10 //<---crouch
canCrouch - crouching allowed //go crouch --- and LOOP
canCrouch Has crouch animation
canCrouch is already crouching - return true //we are crouching ... but the animation isn't
updateMove crouch desiredPose
updateActionThread end action = 10 //<---crouch
pickActionAnimation Ai Stand //<---- www.nooooooooooooooo.com
setActionThread2
updateActionThread end action = 0 //stand root :(
canCrouch - crouching allowed //go crouch and LOOP
...

And the custom code I'm using is from this resource WITHOUT using the nasty hack at the end which drags mPose and NumPoseBits across the read/write system to force the animation to play www.garagegames.com/community/resources/view/22268

Anyone any ideas?

#1
11/29/2013 (4:03 pm)
the only way i know how to do this is in source code using states for an aisoldier class which shouldnt be really that much different from the aiplayer class only difference is you would define the animations in the class itself instead of in torques editor.

aiPlayer.cpp
if (mAimObject) {
      MatrixF eyeMat;
      getEyeTransform(&eyeMat);
      eyeMat.getColumn(3,&location);
      Point3F targetLoc = mAimObject->getBoxCenter();

      // This ray ignores non-static shapes. Cast Ray returns true
      // if it hit something.
      RayInfo dummy;
      if (getContainer()->castRay( location, targetLoc,
            StaticShapeObjectType | StaticObjectType |
            TerrainObjectType, &dummy)) {
         if (mTargetInLOS) {
            throwCallback( "onTargetExitLOS" );
            mTargetInLOS = false;
         }
      }
      else
         if (!mTargetInLOS) {
            throwCallback( "onTargetEnterLOS" );
            mTargetInLOS = true;
         }
   }

I think something like crouching should be implemented here.
#2
11/29/2013 (5:34 pm)
After much back tracing I made sure that mPose was being networked and got rid of the hack which recalls it again.

note: changes made via this resource www.garagegames.com/community/resources/view/22268
void Player::unpackUpdate(NetConnection *con, BitStream *stream)
{
//...

   // MoveMask
   if (stream->readFlag()) {
      mPredictionCount = sMaxPredictionTicks;
      mFalling = stream->readFlag();
      mPose = (Pose)(stream->readInt(NumPoseBits));//yorks in

      ActionState actionState = (ActionState)stream->readInt(NumStateBits);
//...

And some success. It still times out creating a "hop" but only at low fps like <15 and doesn't have the hack of reseting the pose.
#3
11/30/2013 (11:56 am)
Sometimes I see that my (AI)ducks have the same issue when they start or stop swimming. I have applied your fix and it certainly works when calling setPose for assuming a crouch, prone or sprint, but I think that the problem is caused somewhere in the client-server chain, because the serverobject is playing the right sequence/pose while the client still has the old one. This could be caused in the Player::updateMove function where the different poses are checked. Maybe, just maybe, it is possible to add another maskbit and updating the pose whenever it changes, no matter if it is from setPose or from updateMove or whatever. If I find some time I will look into this, but right now i'm to busy hunting bugs in the Master's Eye and I would like to get that thing done before Christmas (although the ducks are one of the minor issues here).
#4
12/02/2013 (9:28 am)
Y'know ... after all this time faffing around, I'd forgotten that Ai has it's own move update ... and it's getting written over by Player where they share the same functions ...

www.yorkshirerifles.com/random/ai_pose_fixed.jpg
I'd call that little issue ...

FIXED!