AIPlayer weapon aim bug
by Howard Dortch · in Torque 3D Professional · 05/13/2016 (6:26 am) · 5 replies
I put a aiplayer in game, he shoots at me but wont hit me
%bot.setAimObject(%player)
%bot.fire(true);
at 20 meters he hits up and left of me
next test I tried this:
%tpos = %player.getWorldBoxCenter();
%bot.setAimLocation(%tpos);
%bot.fire(true);
at 20 meters he hits up and left only worse
checked %bot.getAimLocation() and it is the same as the player worldboxcenter
any one have a clue on how to get the bot to hit me?
%bot.setAimObject(%player)
%bot.fire(true);
at 20 meters he hits up and left of me
next test I tried this:
%tpos = %player.getWorldBoxCenter();
%bot.setAimLocation(%tpos);
%bot.fire(true);
at 20 meters he hits up and left only worse
checked %bot.getAimLocation() and it is the same as the player worldboxcenter
any one have a clue on how to get the bot to hit me?
#2
05/13/2016 (2:06 pm)
I correct for this in scripts/server/weapon.cs:function WeaponImage::onFire(%this, %obj, %slot)
{
//echo("c4WeaponImage::onFire( "@%this.getName()@", "@%obj.client.nameBase@", "@%slot@" )");
// Make sure we have valid data
if (!isObject(%this.projectile))
{
error("WeaponImage::onFire() - Invalid projectile datablock");
return;
}
// Decrement inventory ammo. The image's ammo state is updated
// automatically by the ammo inventory hooks.
if ( !%this.infiniteAmmo )
%obj.decInventory(%this.ammo, 1);
// Get the player's velocity, we'll then add it to that of the projectile
%objectVelocity = %obj.getVelocity();
%numProjectiles = %this.projectileNum;
if (%numProjectiles == 0)
%numProjectiles = 1;
if (%obj.isMemberOfClass("AIPlayer") && isObject(%obj.target))
{
%vec = %obj.getVectorTo(%obj.target.position);
if(%obj.aimOffset)
%vec = VectorAdd(%vec, "0 0 "@%obj.aimOffset);
%vec = VectorNormalize(%vec);
}
else
{
// getting the straight ahead aiming point of the gun
%vec = %obj.getMuzzleVector(%slot);
}
for (%i = 0; %i < %numProjectiles; %i++)
{
if (%this.projectileSpread)
{
// We'll need to "skew" this projectile a little bit. We start by
// Then we'll create a spread matrix by randomly generating x, y, and z
// points in a circle
%matrix = "";
for(%j = 0; %j < 3; %j++)
%matrix = %matrix @ (getRandom() - 0.5) * 2 * 3.1415926 * %this.projectileSpread @ " ";
%mat = MatrixCreateFromEuler(%matrix);
// Which we'll use to alter the projectile's initial vector with
%muzzleVector = MatrixMulVector(%mat, %vec);
}
else
{
// Weapon projectile doesn't have a spread factor so we fire it using
// the straight ahead aiming point of the gun
%muzzleVector = %vec;
}
// Add player's velocity
%muzzleVelocity = VectorAdd(
VectorScale(%muzzleVector, %this.projectile.muzzleVelocity),
VectorScale(%objectVelocity, %this.projectile.velInheritFactor));
// Create the projectile object
%p = new (%this.projectileType)()
{
dataBlock = %this.projectile;
};
%p.initialVelocity = %muzzleVelocity;
%p.initialPosition = %obj.getMuzzlePoint(%slot);
%p.sourceObject = %obj;
%p.sourceSlot = %slot;
%p.client = %obj.client;
%p.sourceClass = %obj.getClassName();
MissionCleanup.add(%p);
}
}note about 24 lines in I check for AIPlayers, then just get a vector from the AI to the target usingfunction AIPlayer::getVectorTo(%this, %pos)
{
if (getWordCount(%pos) < 2 && isObject(%pos))
%pos = %pos.getPosition();
return VectorSub(%pos, %this.getPosition());
}which you could of course just relocate - and modify, perhaps getting vector from muzzle position to target instead.
#3
05/13/2016 (5:27 pm)
Thanks for the info, I see the issue now....
#4
05/13/2016 (7:40 pm)
No problem - this annoyed the hell out of me when I ran into it before and I just happened to have just had my nose in this two weeks ago, so it was fresh in my mind.
#5
07/24/2016 (9:56 am)
this was fixed and was included in the engine
Torque Owner Dwarf King
Noble Games Production
https://www.garagegames.com/community/forums/viewthread/130800
It can be many things. So read that thread first and do some tests.
Also which T3D version are you using?
Also as Steve mentioned in the linked thread, then have a look at the "eyeOffSet". I remember I had to tweek that back then.