Automatic Targeting
by Nicolai Dutka · in Torque Game Engine Advanced · 11/11/2008 (10:46 pm) · 8 replies
I was wondering if anyone was able to setup an automatic targeting system and if they could possibly enlighten me?
I am using resources that lock the camera in a top-down isometric view and need to compensate for angled terrain, so I would like to have the player be able to automatically target enemies and destructible objects within LOS and FOV.
I am using resources that lock the camera in a top-down isometric view and need to compensate for angled terrain, so I would like to have the player be able to automatically target enemies and destructible objects within LOS and FOV.
#2
Off the top of my head, I believe the biggest problem I encountered was getting the player's aim to adjust up/down. I have a resource available showing how to aim the player left/right, but up/down seems to work on everything BUT the control object....
11/23/2008 (7:19 pm)
I still have nothing. I have a functioning prototype of my game and attempting to assemble my team right now, so I am hoping to recruit someone that can set this up. If we get it working, I will certainly post more here. I may even be inclined to write another resource....Off the top of my head, I believe the biggest problem I encountered was getting the player's aim to adjust up/down. I have a resource available showing how to aim the player left/right, but up/down seems to work on everything BUT the control object....
#3
Pseudo Code:
So, making a function or finding one in the engine for setting the pitch of aiming should solve the angled terrain problem. There is already a function for setting the aim on an object, which down deep sets it to a node on that object (A bone or mount point). That function needs to be copied and modified to have it only affect the player's pitch and not the other 2 axis.
As far as 'lock on' solutions, I've thought of a few:
1. Cycle through targets (Like in space sims, and GTAIV) - you can search for this, there is a resource
2. Targeting 1st enemy whose bounding box intersects with player eye ray cast in combination with above code implemented to aid that ray cast.
3. No auto-aim except for pitch, resulting in more twitch style gaming.
For line of sight stuff, check out this post:
www.garagegames.com/mg/forums/result.thread.php?qt=80678
I haven't tried it out yet, but sounds pretty cool and more straight forward than the method in Advanced 3DGPA1 book. Don't know which has better performance yet.
12/08/2008 (10:03 pm)
Haven't worked on this yet, but thought a bit about it.Pseudo Code:
If ( Target.canSee(Player) )
{
Player.setAimPitch( Enemy.someNode );
}So, making a function or finding one in the engine for setting the pitch of aiming should solve the angled terrain problem. There is already a function for setting the aim on an object, which down deep sets it to a node on that object (A bone or mount point). That function needs to be copied and modified to have it only affect the player's pitch and not the other 2 axis.
As far as 'lock on' solutions, I've thought of a few:
1. Cycle through targets (Like in space sims, and GTAIV) - you can search for this, there is a resource
2. Targeting 1st enemy whose bounding box intersects with player eye ray cast in combination with above code implemented to aid that ray cast.
3. No auto-aim except for pitch, resulting in more twitch style gaming.
For line of sight stuff, check out this post:
www.garagegames.com/mg/forums/result.thread.php?qt=80678
I haven't tried it out yet, but sounds pretty cool and more straight forward than the method in Advanced 3DGPA1 book. Don't know which has better performance yet.
#4
12/09/2008 (11:35 am)
That will never work... Sorry, but you CANNOT adjust the pitch of a control object.... It's a limitation of the engine and would require some source code changes. If you know how to do that, then by all means, write us a guide!
#5
To make the player "auto aim" at a vector solution check out a few of the "recoil" resources to see how to manipulate the control object pitch and yaw in code - there's one that does that real well, I just don't remember what it's called.
12/09/2008 (11:47 am)
Well...instead of adjusting the pitch you could adjust the muzzle transform instead - would probably look silly though shooting at something to the side while pointing straight ahead. To make the player "auto aim" at a vector solution check out a few of the "recoil" resources to see how to manipulate the control object pitch and yaw in code - there's one that does that real well, I just don't remember what it's called.
#6
12/09/2008 (5:22 pm)
Yea... I was intending source code changes. I'll post it when I'm done...
#7
There is a section near the bottom of the resource(not the comments) that ports AIPlayer's setaimlocation and setaimobject functions over to the player class. You can use this for a lot of stuff. Little bit of script and you can easily get the player to aim at the closest object. I use it in PrototypeB to aim the player in the direction of the mouse.
12/09/2008 (7:34 pm)
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4077There is a section near the bottom of the resource(not the comments) that ports AIPlayer's setaimlocation and setaimobject functions over to the player class. You can use this for a lot of stuff. Little bit of script and you can easily get the player to aim at the closest object. I use it in PrototypeB to aim the player in the direction of the mouse.
#8
I just got to implementing the intended functionality today. Similarly to that resource, I also looked to the setAimLocation function to help me out. The engine code changes for this are pretty minimal though. I just added 1 function, keeping only the pitch change logic.
player.h, somewhere in Player class, add:
player.cpp, add these functions:
So, only thing I left out here is the script logic to detect an enemy AIPlayer. There's plenty of resources to help with that. When you have your target aquired, just call in script:
12/22/2008 (1:33 am)
Interesting resource, porting setAimLocation. I just got to implementing the intended functionality today. Similarly to that resource, I also looked to the setAimLocation function to help me out. The engine code changes for this are pretty minimal though. I just added 1 function, keeping only the pitch change logic.
player.h, somewhere in Player class, add:
void facePlayerPitch(Player *target);
player.cpp, add these functions:
void Player::facePlayerPitch(Player *target)
{
if(target == NULL)
{
Con::warnf("Player::facePlayerPitch -- target is NULL");
return;
}
MatrixF myEyeMat;
getEyeTransform(&myEyeMat);
Move pMove;
pMove = NullMove;
F32 xDiff = target->getBoxCenter().x - myEyeMat.getPosition().x;
F32 yDiff = target->getBoxCenter().y - myEyeMat.getPosition().y;
if (!isZero(xDiff) || !isZero(yDiff))
{
F32 vertDist = target->getBoxCenter().z - myEyeMat.getPosition().z;
F32 horzDist = mSqrt(xDiff * xDiff + yDiff * yDiff);
F32 newPitch = mAtan( horzDist, vertDist ) - ( M_PI_F / 2.0f );
if (mFabs(newPitch) > 0.01f)
{
Point3F headRotation = getHeadRotation();
pMove.pitch = newPitch - headRotation.x;
}
}
updateMove(&pMove);
}
ConsoleMethod(Player, facePlayerPitch, void, 3, 3, "(target)")
{
Player *targ = NULL;
Sim::findObject(dAtoi(argv[2]), targ);
object->facePlayerPitch(targ);
}So, only thing I left out here is the script logic to detect an enemy AIPlayer. There's plenty of resources to help with that. When you have your target aquired, just call in script:
%player.facePlayerPitch(%target) //Where %target is an AIPlayer Object, and %player is the controlling player
Torque Owner Dante Falcone