Having problem with aim offset

Scripting questions, discussions, etc
  • 1
  • 2
17 posts Page 1 of 2
XIXWYRMEXIX
Posts: 5
Joined: Sat Mar 07, 2015 3:13 pm
by XIXWYRMEXIX » Sun Jun 05, 2016 7:07 pm
Hi, I have been delving into AI with Torque 3D, so that being the case I have been doing some of the different tutorials. I am having a problem with the aim of the bot from Steve Acastors Simple FPS Tutorial. Everything other than the aim of the bot works fine, I can spawn with different weapons (I used the Ryder and Lurker) and spawn at points I specify. The bots function fine, with the console logs showing the thinking echos. The aim of the bot shoots up and to the left completely missing the player target unless the player is almost on top of the bot. I have played with different numerical values in the bot script for aim offset and nothing seems to change or affect the bad aim. I am guessing perhaps it is being overridden somewhere somehow?

Any help or information would be great. I am using torque 3.8.
Johxz
Posts: 395
Joined: Sat Feb 07, 2015 11:37 pm
by Johxz » Sun Jun 05, 2016 8:32 pm
I don't remember having any issuing with the bot aim. You already did this tutorial? http://wiki.torque3d.org/scripter:how-d ... ed-with-ai
XIXWYRMEXIX
Posts: 5
Joined: Sat Mar 07, 2015 3:13 pm
by XIXWYRMEXIX » Sun Jun 05, 2016 10:53 pm
I did that tutorial ages ago (literally years ago). I am doing Steves Acastors Simple FPS. I realize it is made for 1.2 (which I own) but I am attempting it on 3.8. As I said everything else works perfectly. Here is the function-

01.function AIPlayer::attackTarget(%this, %target)
02.{
03. echo(%this.getname() @ " attacking!");
04. %this.setAimObject(%target, "0 0 1.5");
05. %this.schedule(150, "shoot");
06. // a slight delay to make sure we're aiming at the target
07. //you could always use a raycast to see if the target is in the bot's sights instead
08.}
09.

It does not matter what value I place, or where in the offset parameters, the Bot always and only shoots up and to the left. I have changed the value to 1, to .75 to 2, there is no perceptible change. Either something changed between 1.2 and 3.8 or I am missing something somewhere. Probably the latter. That's why I was asking about the aim offset being over ridden somewhere, somehow. To me it does not make sense. According to what I have researched, the tutorials I have done and what I know of the setAimObject I should not have this issue. And I should be able to edit the offset and see a difference. So it seems either something has changed, or I am missing something somewhere.
XIXWYRMEXIX
Posts: 5
Joined: Sat Mar 07, 2015 3:13 pm
by XIXWYRMEXIX » Sun Jun 05, 2016 11:30 pm
Just did a quick test with the console commands and spawning a bot. The problem is still there with console commands. The setAimObject seems to not work with the console commands either. I have not changed anything in the game other than the tutorial bot scripts so this is a stock 3.8 level with nothing in it except the terrain. I am perplexed.
Johxz
Posts: 395
Joined: Sat Feb 07, 2015 11:37 pm
by Johxz » Mon Jun 06, 2016 12:18 am
ok let me check in my t3d v3.8 because I'm remember doing this "3.5) Bob has pretty poor aim" from the wiki tutorial that I give you.
Johxz
Posts: 395
Joined: Sat Feb 07, 2015 11:37 pm
by Johxz » Mon Jun 06, 2016 2:41 am
btw you saw this thread? AIPlayer weapon aim bug - http://www.garagegames.com/community/fo ... ead/143213
Johxz
Posts: 395
Joined: Sat Feb 07, 2015 11:37 pm
by Johxz » Mon Jun 06, 2016 6:26 am
Check eyeoffset: http://garagegames.com/community/resources/view/21614/1

datablock ShapeBaseImageData(AiLurkerWeaponImage)  
{
// Basic Item properties
shapeFile = "art/shapes/weapons/Lurker/TP_Lurker.DAE";
emap = true;

imageAnimPrefix = "Rifle";

// Specify mount point & offset for 3rd person, and eye offset
// for first person rendering.
mountPoint = 0;
firstPerson = false;
useEyeNode = false;
animateOnServer = false;
eyeOffset = "0.0 0.6 -0.1"; // right/left forward/backward, up/down
//...
rlranft
Posts: 298
Joined: Thu Feb 05, 2015 3:11 pm
 
by rlranft » Mon Jun 06, 2016 3:32 pm
Eye offset is one option - I just modified WeaponImage::onFire() to get the muzzle point and calc the aim vector from that for AI units:
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);
}
}

I then added this AIPlayer method:
function AIPlayer::getVectorTo(%this, %target)
{
if (getWordCount(%pos) < 2 && isObject(%target))
%pos = %target.getPosition();

%z = getWord(%this.boundingBox, 2) / 2;
%offset = "0 0" SPC %z;

%vec = VectorAdd(%offset, %this.getPosition());

%z = getWord(%target.boundingBox, 2) / 2;
%offset = "0 0" SPC %z;

%pos = VectorAdd(%offset, %pos);

return VectorSub(%pos, %vec);
}
Johxz
Posts: 395
Joined: Sat Feb 07, 2015 11:37 pm
by Johxz » Tue Jun 07, 2016 1:48 am
@
User avatar
rlranft
you fix would be merge with the main branch?
rlranft
Posts: 298
Joined: Thu Feb 05, 2015 3:11 pm
 
by rlranft » Tue Jun 07, 2016 3:24 am
Well, I doubt it - it's only necessary (or useful) if a game uses AIPlayer. If not, it's just extra work.
  • 1
  • 2
17 posts Page 1 of 2

Who is online

Users browsing this forum: No registered users and 1 guest