Game Development Community

SetAimObject hits the feet

by Howard Dortch · in Torque Game Engine · 07/14/2004 (9:23 am) · 24 replies

I set my bot to shoot at a target (like me) and it only shoots my feet. Is there some adjustment I can make so it shoots at my body or head? Problem is the bot can cast a ray and see my body but shoots into the landscape in front of me if im behind a little hill.
Page «Previous 1 2
#1
07/14/2004 (10:19 am)
In game/AIPlayer.h
line 38 add:
Point3F mAimOffset;

line 52 add:
void setAimObject( GameBase *targetObject, Point3F offset );

In game/AIPlayer.cc
line 26 in AIPlayer() add:
mAimOffset = Point3F(0.0f, 0.0f, 0.0f);

line 88 add:
/**
 * Sets the object the bot is targeting and an offset to add to target location
 *
 * @param targetObject The object to target
 * @param offset       The offest from the target location to aim at
 */
void AIPlayer::setAimObject( GameBase *targetObject, Point3F offset )
{   
   mAimObject = targetObject;
   mTargetInLOS = false;
   mAimOffset = offset;
}

line 111 in setAimLocation() add:
mAimOffset = Point3F(0.0f, 0.0f, 0.0f);

line 122 in clearAim() add:
mAimOffset = Point3F(0.0f, 0.0f, 0.0f);


line 146 in getAIMove() change:
mAimLocation = mAimObject->getPosition();
to
mAimLocation = mAimObject->getPosition() + mAimOffset;

line 378 change:
ConsoleMethod( AIPlayer, setAimObject, void, 3, 4, "( GameBase obj )"
              "Sets the bot's target object. Optionally set an offset from target location.")
{  
   // Find the target
   GameBase *targetObject;
   if( Sim::findObject( argv[2], targetObject ) )
      object->setAimObject( targetObject );
   else
      object->setAimObject( 0 );
}

to

ConsoleMethod( AIPlayer, setAimObject, void, 3, 4, "( GameBase obj, [Point3F offset] )"
              "Sets the bot's target object. Optionally set an offset from target location.")
{  
   Point3F off( 0.0f, 0.0f, 0.0f );

   // Find the target
   GameBase *targetObject;
   if( Sim::findObject( argv[2], targetObject ) )
   {
      if (argc == 4)
         dSscanf( argv[3], "%f %f %f", &off.x, &off.y, &off.z );

      object->setAimObject( targetObject, off );
   }
   else
      object->setAimObject( 0, off );
}
#2
10/09/2004 (4:51 am)
Although Matthews approach is certainly a viable one that is controllable I think it may be a little overkill in this case. I solved the problem by changing line 175 in aiPlayer.cc from...

F32 vertDist = mAimLocation.z - location.z;

to...


F32 vertDist = mAimLocation.z - (location.z - 1.0);


to give the Bot a 1 TU lift from the ground position. Since your players are normally 2 TU's in height it will basically target dead center of the target. You could stick a random number from one to two in there to give the Bot a somewhat random aim and to allow for head shots and such(if you need it), but to get a bot to just try and flat out to kill you, the above change should get him to kick your butt pretty fast.
#3
10/09/2004 (6:43 am)
I have been experimenting with different methods and situations. Take the case where you are some distance from the bot peeking over a hill, bot shouldn't see you so easy. If you are close and peek over a wall the bot has a better chance to see you. So if yer close bot should do a head shot or is more apt to hit you and far away perhapps most of the body needs exposed for a shot. Trying to make the bots more realistic.
Thanks for the idea Gonzo, will ponder it a bit.
#4
10/27/2004 (6:09 pm)
@Matthew in the function setAimObject( GameBase *targetObject, Point3F offset ) should one of the members be the offset?

void AIPlayer::setAimObject( GameBase *targetObject, Point3F offset )
{
mAimObject = targetObject;
mTargetInLOS = false;
mAimOffset = offset; <<<<<<<<< this needs added?

}
#5
11/05/2004 (6:29 pm)
You know, it just occured to me that you could probably set the bot to shoot at the players head by using..

%bot.setAimObject(%obj.camera);

Since the camera is mounted to the eye node.
#6
11/05/2004 (6:33 pm)
The camera is not mounted to the player's head.

You could use
%bot.setAimLocation(%target.getEyePoint());
#7
11/05/2004 (6:35 pm)
@Gonzo, to shoot the head we can also use the eyeTransform() as an aim point.
#8
11/05/2004 (7:57 pm)
Just before IGC, I actually added this code to BoomBall and caught a couple of bugs (which I fixed in the post above). This little snippet is pretty handy when I wanted to add some random innaccuracy and/or target leading to the bots.
#9
11/05/2004 (8:03 pm)
On my todolist.
#10
11/05/2004 (8:41 pm)
%bot.setAimLocation(%target.getEyePoint());

and

%bot.setAimObject(%obj.camera);


are two different things.


Setting the aim object will cause the bot to follow the movements of that object

Seting the aimPoint will cause the bot to point at that spot. If the player steps just a bit to the side, the bot would no longer be aiming at him. You would have to keep updating his aim point . There are plenty of ways to shoot at a bot for sure, but locking onto the head was what I was trying to accomplish vesus aiming at the head.
#11
11/06/2004 (4:19 am)
Can the character models have a head node or head mountpoint that can be aquired? Since we have the player object that the bot is shooting at is there a way to traverse the player object mesh to determine that? Simple C++ code like Matthew's offset method might be used for that sort of thing.
#12
11/06/2004 (1:49 pm)
Matthew's technique deals with this whole problem, nicely... You figure out the offset from the origin of the object you want to aim at, and specify it to the aimObject call. Or am I missing something?
#13
11/06/2004 (3:44 pm)
Quote:Matthew's technique deals with this whole problem, nicely... You figure out the offset from the origin of the object you want to aim at, and specify it to the aimObject call. Or am I missing something?



You could do the same thing in script by using setAimObject on the target until just before the bot is ready to fire, then you could easily retarget the head by using...

%bot.setAimLocation(vectorAdd(%target.getPosition(), "0 0 1.8"));
%bot.fire();
%bot.setAimObject(%target);
#14
11/06/2004 (3:47 pm)
@Ben - Matthews method works just as advertised. The only problem you would have here is having players of different heights but thats easy to compensate for.
#15
11/06/2004 (4:07 pm)
Yup... just calculate an offset based on the target.
#16
11/06/2004 (8:32 pm)
Actually yes, you could set variables directly on the player like so....


%player.aiAimHeight = "0 0 1.8";

or even short players...

%player.aiAimHeight = "0 0 0.9";

then you would just use...


%bot.setAimLocation(vectorAdd(%player.getPosition(), %player.aiAimHeight));
%bot.fire();
%bot.setAimObject(%player);
#17
11/07/2004 (12:01 am)
When I wanted the bots to shoot at the "head" of an object I exposed a getHeight() ConsoleMethod on all GameBase objects which returns the height of the bounding box and then used %'s of that height as offsets to shoot at the "head", "chest", "stomach", "crotch", "thighs", or "shins".
#18
11/07/2004 (3:16 am)
In the console method for the offset it looks like the function call is wanting the values as an ascii so the input for the offset is "0 0 1.5" how can I substitute a Point3F value? I'm trying to set the x,y values to lead the target a bit since bots shoot behind me when I run. I tried to do this "%aim.x %aim.y 1.5" but that wont work. Do I write another overloaded func to take 3 numbers?
#19
11/07/2004 (10:34 pm)
%bot.SetAimObject(%target, %aim.x SPC %aim.y SPC "1.5");
#20
12/19/2005 (7:50 am)
I hate to dredge this up again but I have a strange problem.
I integrated Matts idea in the engine and the bot shoots into the ground in front of me but shouldn't

here is a snippet:

%this.setAimObject(%object,"0.0 0.0 2.0");

echo("MY POS "@%object.getPosition()); <<< this prints 100 176 90

echo("BOT AIM "@%this.getAimLocation()); <<< this prints 100 176 92

The bot should be shooting my player in the head but shoots the ground in front of me. Any Ideas here?
Page «Previous 1 2