### aiPlayer aim

Scripting questions, discussions, etc
• 1
• 2

#### aiPlayer aim

Hodo33
Posts: 42
Joined: Fri Dec 29, 2017 4:34 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?

#### Re: aiPlayer aim

Hodo33
Posts: 42
Joined: Fri Dec 29, 2017 4:34 pm
Bump .... anyone point me to where this fails? Is this a bug?

#### Re: aiPlayer aim

NeonTiger
Posts: 3
Joined: Sun Aug 02, 2015 4:50 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)
// {
// }

#### Re: aiPlayer aim

Hodo33
Posts: 42
Joined: Fri Dec 29, 2017 4:34 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....

#### Re: aiPlayer aim

Steve_Yorkshire
Posts: 294
Joined: Tue Feb 03, 2015 10:30 pm

Latest dev branch stock code:
%bot.setAimObject(%player, "0 0 1.5"); %bot.fire(1);// is hitting pretty dead centre.

#### Re: aiPlayer aim

Steve_Yorkshire
Posts: 294
Joined: Tue Feb 03, 2015 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.

#### Re: aiPlayer aim

Steve_Yorkshire
Posts: 294
Joined: Tue Feb 03, 2015 10:30 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)

#### Re: aiPlayer aim

Hodo33
Posts: 42
Joined: Fri Dec 29, 2017 4:34 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.....

#### Re: aiPlayer aim

Steve_Yorkshire
Posts: 294
Joined: Tue Feb 03, 2015 10:30 pm

To build 3.10 you need the latest version of CMake (3.12) and Visual Studio 2017

#### Re: aiPlayer aim

Steve_Yorkshire
Posts: 294
Joined: Tue Feb 03, 2015 10:30 pm

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;

// Weapon lights up while firing
lightType = "WeaponFireLight";
lightColor = "0.976 0.65 0.101 1";
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
// 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";
stateTransitionOnNoAmmo[0]       = "NoAmmo";

// Activating the gun.  Called when the weapon is first
// mounted and there is ammo.
stateName[1]                     = "Activate";
stateTimeoutValue[1]             = 0.1;
stateSequence[1]                 = "Activate";

// Ready to fire, just waiting for the trigger
stateTransitionOnNoAmmo[2]       = "NoAmmo";
stateTransitionOnTriggerDown[2]  = "Fire";

// Fire the weapon. Calls the fire script which does
// the actual work.
stateName[3]                     = "Fire";
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
stateTransitionOnNoAmmo[4]       = "NoAmmo";
stateWaitForTimeout[4]           = "0";
stateTimeoutValue[4]             = 0.5;//0.1
stateAllowImageChange[4]         = false;

// No ammo in the weapon, just idle until something
// shows up. Play the dry fire sound if the trigger is
// pulled.
stateName[5]                     = "NoAmmo";
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

#### Who is online

Users browsing this forum: No registered users and 3 guests