Game Development Community

T3D 1.2 - AIPlayers don't aim correctly using the new weapons

by Guy Allard · in Torque 3D Professional · 06/17/2012 (10:47 am) · 8 replies

Build: all
Platform: all
Target: FPS Example

Issues:
The aim of AIPlayers is screwed up by the new weapons. They consistently aim high and to the right of the target.

Steps to repeat:
Load FPSExample.
Start empty mission.

enter the following in the console, or exec it from a script:
$bob = AIPlayer::spawn("bob", VectorAdd(localClientConnection.player.getPosition(), VectorScale(localClientConnection.player.getForwardVector(), 20)));
$bob.setInventory(Lurker, 1);
$bob.setInventory(LurkerAmmo, $bob.maxInventory(LurkerAmmo));
$bob.setInventory(LurkerClip, $bob.maxInventory(LurkerClip));
$bob.mountImage(LurkerWeaponImage, 0);
$bob.setAimObject(localClientConnection.player);
$bob.setImageTrigger(0, 1);

Bob will miss you.

To really see what's happening, give the BulletProjectile a shape, slow its muzzleVelocity down to 10 or 15 and watch where it goes. Removing the projectile spread from the lurker will also help illustrate the problem, as you will then see a tight stream of projectiles going high and to the side of your player.

This is also a problem with the Ryder, and also the grenade launcher, although the large spread of the grenade launcher masks the issue to some extent.

AIPlayers are still deadly with the old RocketLauncher, so the issue is with the new weapons, possibly an unwanted side effect of the new attention deficit disorder animations introduced in the latest version.

#1
06/17/2012 (11:05 am)
"attention deficit disorder animations" -- lol, I like that!

eyeOffset or correctMuzzleVector is the likely culprit
#2
06/17/2012 (11:21 am)
:) the credit for that goes to Steve and his critique of Far Cry 2.

Setting correctMuzzleVector = false; doesn't solve the issue.
#3
06/17/2012 (11:55 am)
The constant clicking annoys the hell out of me ... Soldier needs Ritalin. When testing with the stock player I disable audio ...

I do remember a code fix for something like this done by ... I was thinking either Enel or piggy - Szzg007 - from sometime ago but after looking at both of their threads I don't see it ... :/
#4
06/17/2012 (11:59 am)
Having said that, and after using your code I see that the aim is going wide to the left ...

Maybe some sort of swearing at the search engine will help!
#5
06/17/2012 (3:53 pm)
Seems like the aim is consistant with the hold pose for the weapon. If you alt-C to the editor cam and look at the bot from above it looks like the projectiles are traveling at the angle the animation has him holding the gun at.

If you turn off correctMuzzleVector and then fire your own Lurker it has about the same aim offset.

Maybe AIPlayer needs its own version of correctMuzzleVector, firing towards the point the bot is aiming at instead of the camera vector? Try this out:

in aiPlayer.h, add this:
void clearAim();

   // [NEWCODE] AI Player's Corrected Aim
   void AIPlayer::getMuzzleVector(U32 imageSlot,VectorF* vec);
   // [/NEWCODE]

   // Movement sets/gets
   void setMoveSpeed( const F32 speed );

and then the function in aiPlayer.cpp:

void AIPlayer::getMuzzleVector(U32 imageSlot,VectorF* vec)
{
   MatrixF mat;
   getMuzzleTransform(imageSlot,&mat);

   MountedImage& image = mMountedImageList[imageSlot];

   if (image.dataBlock->correctMuzzleVector)
   {
      disableHeadZCalc();
      if (getCorrectedAim(mat, vec))
      {
         enableHeadZCalc();
         return;
      }
      enableHeadZCalc();
   }
   mat.getColumn(1,vec);
}

I put them right after AIPlayer::clearAim, made sense to me. I was going to write a version of getCorrectedAim for AIPlayer but it apparently works fine as is; it can get the "cameraTransform" even though there's no camera (I assume it's the same as eye transform in this case).

I remember working with bots with previous versions and not having this issue, but think it's because they had perfectly forward weapon holding animations. This should also fix issues with look up/down animations not quite matching where the AIPlayer should be aiming.
#6
06/18/2012 (7:24 pm)
Oh, sweet! I was having this problem while revamping the RTS Prototype. I've got them multi-selecting, moving in formations, spawning from "barracks," but they still aim like they don't know what to do with the gun....

Good work Henry!

Oh, wait. That's a source change. Darn!
#7
06/19/2012 (7:14 am)
Richard, if you use the "eyeOffSet" in the weaponImage datablock your Ai will spawn their projectiles relative to their eyeNode.

Easy scripting change for the RTS tut.
#8
06/19/2012 (7:13 pm)
Good news Steve - I knew you had mentioned that before but I couldn't remember the variable. Thanks!