aiPlayer aim

Scripting questions, discussions, etc
  • 1
  • 2
13 posts Page 1 of 2
Hodo33
Posts: 42
Joined: Fri Dec 29, 2017 4:34 pm
by Hodo33 » Wed Jul 18, 2018 5:41 pm
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?
Hodo33
Posts: 42
Joined: Fri Dec 29, 2017 4:34 pm
by Hodo33 » Sun Jul 22, 2018 10:56 pm
Bump .... anyone point me to where this fails? Is this a bug?
NeonTiger
Posts: 3
Joined: Sun Aug 02, 2015 4:50 am
by NeonTiger » Mon Jul 23, 2018 12:04 am
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;
// }
Hodo33
Posts: 42
Joined: Fri Dec 29, 2017 4:34 pm
by Hodo33 » Mon Jul 23, 2018 4:35 pm
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....
Steve_Yorkshire
Posts: 294
Joined: Tue Feb 03, 2015 10:30 pm
 
by Steve_Yorkshire » Mon Jul 23, 2018 10:19 pm
Latest dev branch stock code:
%bot.setAimObject(%player, "0 0 1.5"); %bot.fire(1);// is hitting pretty dead centre.
Steve_Yorkshire
Posts: 294
Joined: Tue Feb 03, 2015 10:30 pm
 
by Steve_Yorkshire » Mon Jul 23, 2018 10:30 pm
Having said that I do remember an issue when AI couldn't aim correctly due to "look" and "head" animations being wrong (or not being synchronized or something). That might affect a new or custom player model but shouldn't affect the stock soldier model.
Steve_Yorkshire
Posts: 294
Joined: Tue Feb 03, 2015 10:30 pm
 
by Steve_Yorkshire » Mon Jul 23, 2018 11:59 pm
Actually I did find an old 3.8 version and Ai doesn't seem very capable of hitting squat (though no idea how much I might have modded the code for this thing)
Hodo33
Posts: 42
Joined: Fri Dec 29, 2017 4:34 pm
by Hodo33 » Tue Jul 24, 2018 1:56 pm
Don't suppose I can use that 3.10 file in my 3.8 build ? Not having any luck building 3.10
Somewhere the aim offset is getting changed, I'll keep after it till I find it..
Thanks.....
Steve_Yorkshire
Posts: 294
Joined: Tue Feb 03, 2015 10:30 pm
 
by Steve_Yorkshire » Wed Jul 25, 2018 6:09 pm
To build 3.10 you need the latest version of CMake (3.12) and Visual Studio 2017
Steve_Yorkshire
Posts: 294
Joined: Tue Feb 03, 2015 10:30 pm
 
by Steve_Yorkshire » Fri Aug 03, 2018 4:11 am
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";
};
  • 1
  • 2
13 posts Page 1 of 2

Who is online

Users browsing this forum: No registered users and 3 guests