Improved AIming
by Nathan Kent · 07/08/2008 (8:50 am) · 1 comments
Download Code File
To use this, all you have to do is replace the Player.cc/h and AIPlayer.cc/h files with the ones included. They were made using stock TGE1.5.2, so if you are using a modified version, TGEA, or TGE with AFX, than you can search for '// AIm ->' at the beginning of changes, and '// AIm <-' at the end of them.
What this will do is allow you to specify a bone in any ShapeBase that you want the AIPlayer to target (if the target is a Player, and no node is specified, than it will default to the eye node). This will also improve the Line-of-sight check so that it will raycast to several different nodes in a Player (this assumes that you are using the default skeleton), and returns if it can see any of them.
Right now, it's not terribly accurate, but it should suffice in most situations. I think the problem lies in parts of Torque that I've never explored, but it's very possible that the problem is my code.
Console Functions:
Update: Monday, July 28, 2008 15:05: AIPlayer.getAimNode() now returns the string name of the targeted node.
To use this, all you have to do is replace the Player.cc/h and AIPlayer.cc/h files with the ones included. They were made using stock TGE1.5.2, so if you are using a modified version, TGEA, or TGE with AFX, than you can search for '// AIm ->' at the beginning of changes, and '// AIm <-' at the end of them.
What this will do is allow you to specify a bone in any ShapeBase that you want the AIPlayer to target (if the target is a Player, and no node is specified, than it will default to the eye node). This will also improve the Line-of-sight check so that it will raycast to several different nodes in a Player (this assumes that you are using the default skeleton), and returns if it can see any of them.
Right now, it's not terribly accurate, but it should suffice in most situations. I think the problem lies in parts of Torque that I've never explored, but it's very possible that the problem is my code.
Console Functions:
AIPlayer.setAimObject(Object, [offset, node]); // Node is the string name of the bone AIPlayer.getAimObject(); AIPlayer.clearAim(); // Clears everything // AIPlayer.setAimNode(node); // Node is the string name of the bone AIPlayer.getAimNode(); // Returns the string name of targeted node AIPlayer.clearAimNode(); // Set's the aim node back to default (The Eye node for Players/AIPlayers, Position for everything else) // AIPlayer.setAimOffset(offset); // Point3F offset AIPlayer.getAimOffset(); AIPlayer.clearAimOffset(); // Player::isInLOS(Target); // Checks to see if the target is in sight (from the eye position). If target is a child of Player, than it will raycast to a set of bones. Otherwise to the targets box center.
Update: Monday, July 28, 2008 15:05: AIPlayer.getAimNode() now returns the string name of the targeted node.

Sailendu Behera