Jump to content

aiPlayer aim


Hodo33

Recommended Posts

using version 3.8


%bot.setAimObject(%player,"0 0 3.0"); supposed to be aim and my player with offset. No matter what I put in the z offset bot shoots my legs


%aim = %player.getWorldBoxCenter();

%aim = setWord(%aim,2,getWord(%aim,2) + 2);

%bot.setAimLocation(%aim); no matter the value I add to z the bot shoots me in the legs


can someone clarify how I can use the setAimObject with offset so the bot hits me in the chest or head?

Same with setAimLocation what am I doing wrong?


I get my player position before applying the offset

592.401 -480.159 128.553

here is the value after

592.401 -480.159 131.478


bot shoots me in the legs


help?

Link to comment
Share on other sites

I tried the code you posted above in 3.10 and seems to work. Are you doing this at a long distance? When i was messing around with AI back in T3D 1.2 i ran into an aiming issue.


Going off memory, it was something with this if block in aiplayer.cpp

if (mFabs(newPitch) > 0.01f)


i think i just commented out that if statement and left the other two lines alone. That seemed to fix my aim precision issue. With that said, its not a fix just me trouble shooting so this may still cause problems.


// if (mFabs(newPitch) > 0.01f)

// {

Point3F headRotation = getHeadRotation();

movePtr->pitch = newPitch - headRotation.x;

// }

Link to comment
Share on other sites

I changed the getposition in the engine to getworldboxcenter and got same result. I changed the offset to 0 0 12 and still shots my feet.

As for distance if I am 10 to 15 meters he shoots my chest, beyond that always at my feet for aimobject and aimlocation I will have a look at the pitch routine and play with it some, thanks for the reply....

Link to comment
Share on other sites

  • 2 weeks later...

Hey @Hodo33 I was doing a bit of digging around on how I used to do Ai aiming from my released turn-based game (which is all AI, no players) and there are a couple of things that you can do in the ShapeBaseImageData(YourWeaponImage).

First up is adding an offset to the eye which will force aiming via the eye.


eyeOffset = "0.0 0.0 0.1";

This will make a tiny vertical offset but force the weapon to use the eye (might need a head animation) for aiming.


Alternatively you can use muzzleCorrection and force the aim to intersect with the eyeVector.


correctMuzzleVector = true;


I've tested both of these methods in Torque 3.8 and Torque 3.10.1 and they both seem good with my custom aiplayerand weapon models and custom animations.

%ai.setaimlocation(%playerName.getEyePoint());//<--- gives a good head shot!


Anyhow, here's what my test weaponImage data looked like.

datablock ShapeBaseImageData(TestRifleImage)
{
   // Basic Item properties
   shapefile = "art/shapes/yorksTest/rifle_standard.dts";//your shape goes <---------------------------------------here
   emap = true;
 
   imageAnimPrefix = "Rifle";
   imageAnimPrefixFP = "Rifle";
 
   infiniteAmmo = 1;
 
   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   firstPerson = true;
   useEyeNode = false;//true;//this doesn not help AI to aim
   animateOnServer = true;
 
   // The model may be backwards
   // rotation = "0.0 0.0 1.0 180.0";
   // eyeRotation = "0.0 0.0 1.0 180.0";
 
   // When firing from a point offset from the eye, muzzle correction
   // will adjust the muzzle vector to point to the eye LOS point.
   // Since this weapon doesn't actually fire from the muzzle point,
   // we need to turn this off.
   correctMuzzleVector = true;//use this <---------------------------------------here
   //eyeOffset = "0.0 0.0 0.1";//or this <------------------------------------------here
 
   // Add the WeaponImage namespace as a parent, WeaponImage namespace
   // provides some hooks into the inventory system.
   class = "WeaponImage";
   className = "WeaponImage";
 
   // Projectiles and Ammo.
   item = TestRifle;
   ammo = TestRifleAmmo;
 
   projectile = TestRifleProjectile;
   projectileType = Projectile;
   projectileSpread = "0.0";
 
   // Weapon lights up while firing
   lightType = "WeaponFireLight";
   lightColor = "0.976 0.65 0.101 1";
   lightRadius = "10";
   lightDuration = "100";
   lightBrightness = 3;
 
   // Shake camera while firing.
   shakeCamera = false;
   camShakeFreq = "0 0 0";
   camShakeAmp = "0 0 0";
 
   casing = BulletShell;
   shellExitDir        = "1.0 0.3 1.0";
   shellExitOffset     = "0.15 -0.56 -0.1";
   shellExitVariance   = 15.0;
   shellVelocity       = 1.0;
 
   // Images have a state system which controls how the animations
   // are run, which sounds are played, script callbacks, etc. This
   // state system is downloaded to the client so that clients can
   // predict state changes and animate accordingly.  The following
   // system supports basic ready->fire->reload transitions as
   // well as a no-ammo->dryfire idle state.
 
   useRemainderDT = false;//true;//allow multiple state timeouts in a single tick
 
   // Initial start up state
   stateName[0]                     = "Preactivate";
   stateTransitionOnLoaded[0]       = "Activate";
   stateTransitionOnNoAmmo[0]       = "NoAmmo";
 
   // Activating the gun.  Called when the weapon is first
   // mounted and there is ammo.
   stateName[1]                     = "Activate";
   stateTransitionOnTimeout[1]      = "Ready";
   stateTimeoutValue[1]             = 0.1;
   stateSequence[1]                 = "Activate";
 
   // Ready to fire, just waiting for the trigger
   stateName[2]                     = "Ready";
   stateTransitionOnNoAmmo[2]       = "NoAmmo";
   stateTransitionOnTriggerDown[2]  = "Fire";
 
   // Fire the weapon. Calls the fire script which does
   // the actual work.
   stateName[3]                     = "Fire";
   stateTransitionOnTimeout[3]      = "Reload";
   stateTimeoutValue[3]             = 0.1;//0.09
   stateFire[3]                     = true;
   stateRecoil[3]                   = "";
   stateAllowImageChange[3]         = false;
   stateSequence[3]                 = "fire";
   stateScaleAnimation[3]           = true;
   stateScript[3]                   = "onFire";
   stateSound[3]                    = LurkerFireSound;//BulletFireSound;
   stateEmitter[3]                  = GunFireSmokeEmitter;
   stateEmitterTime[3]              = 0.08;//0.025;
   stateEjectShell[3]               = true;
 
   // Play the reload animation, and transition into
   stateName[4]                     = "Reload";
   stateTransitionOnNoAmmo[4]       = "NoAmmo";
   stateTransitionOnTimeout[4]      = "Ready";
   stateWaitForTimeout[4]           = "0";
   stateTimeoutValue[4]             = 0.5;//0.1
   stateAllowImageChange[4]         = false;
   stateSequence[4]                 = "Reload";
 
   // No ammo in the weapon, just idle until something
   // shows up. Play the dry fire sound if the trigger is
   // pulled.
   stateName[5]                     = "NoAmmo";
   stateTransitionOnAmmo[5]         = "Reload";
   stateSequence[5]                 = "NoAmmo";
   stateTransitionOnTriggerDown[5]  = "DryFire";
 
   // No ammo dry fire
   stateName[6]                     = "DryFire";
   stateTimeoutValue[6]             = 0.1;
   stateTransitionOnTimeout[6]      = "NoAmmo";
   stateScript[6]                   = "onDryFire";
};
Link to comment
Share on other sites

@Hodo33 Got a fix for you. :mrgreen:

The reason this is happening is that the further the distance from the target, the smaller the aim rotation change and the default code setting ignores anything under 0.01f. Aiming at a playerObject near his eyeNode and at the same position height makes the rotation change even smaller.


Check out these pics, no change in LOS at range (~70 units) between z offset 0 and +0.5, but definite aim change up close between +0.5 and +1.0.

https://imgur.com/a/Wfcj1Xh


VHKwVq8.jpg


Changing AIplayer.cpp ~line 478 in getAiMove to make default ignore rotation smaller. I added 2 more zeros as 1 didn't seem enough at >100m distance.

//..
            // This should be adjusted to run from the
            // eye point to the object's center position. Though this
            // works well enough for now.
            F32 vertDist = mAimLocation.z - location.z;
            F32 horzDist = mSqrt(xDiff * xDiff + yDiff * yDiff);
            F32 newPitch = mAtan2( horzDist, vertDist ) - ( M_PI_F / 2.0f );
            if (mFabs(newPitch) > 0.0001f)//yorks was 0.01
            {
               Point3F headRotation = getHeadRotation();
               movePtr->pitch = newPitch - headRotation.x;
            }
//..

 

And this is the difference at 120 units.

75r0Kxc.jpg


@Azaezel @JeffR maybe one for rolling into development? (you know github hates me :lol: )


[EDIT]

Just to note, this is using the standard Lurker file only with projectile spread set to 0 and projectileData lifetime very much increased - just for testing, it doesn't use the eyeOffSet value which I suggested earlier in this thread (so you can ignore that).

datablock ShapeBaseImageData(LurkerWeaponImage)
{
   // Basic Item properties
   shapeFile = "art/shapes/weapons/Lurker/TP_Lurker.DAE";
   shapeFileFP = "art/shapes/weapons/Lurker/FP_Lurker.DAE";
   emap = true;
 
   imageAnimPrefix = "Rifle";
   imageAnimPrefixFP = "Rifle";
 
   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   firstPerson = true;
   useEyeNode = true;
   animateOnServer = true;
 
   // When firing from a point offset from the eye, muzzle correction
   // will adjust the muzzle vector to point to the eye LOS point.
   // Since this weapon doesn't actually fire from the muzzle point,
   // we need to turn this off.
   correctMuzzleVector = true;
//... etc etc

 

This newPitch setting of 0.0001f, gives pitch offset increments of z +1.0 at 650 metres/units - which is way more than visual distance.

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...