Game Development Community

Confused about implementing AIManager and AIPLayer

by SaurabhTorne · in Torque Game Engine · 12/30/2006 (10:35 pm) · 9 replies

Hi
I am pretty confused about how to implement AIManager and AIplayer
What is the the difference between AImanager and AIPlayer. What is the Think function supposed to do. How is it determined that a bot has reached his movedestination.

Currently I am doing only scripting. Thankyou

#1
12/30/2006 (11:11 pm)
1) AIManager is a generic script manager. AIPlayer is a C++ class.

2) the think function in its original form is supposed to schedule spawns when a player dies. It is meant to be easily expandable, so that you can add your own things to the think function. It schedules a call to itself and allows the player to "think" everytime its called. (no there is no actual thinking happening in its original form)

3) onReachDestination is called from the engine.

Let me know if you want more depth. Hope i helped some!
#2
12/30/2006 (11:42 pm)
Thanks william,
Is OnReachDestination called when bots reaches its destination. Is it a callback function.
Do I have to put the code that will command bot to next target in this function
#3
12/31/2006 (8:10 am)
function AIManager::spawn(%this)
{
   %player = AIPlayer::spawnOnPath("Kork","MissionGroup/Paths/Path1");
   %player.followPath("MissionGroup/Paths/Path1",-1);

   %player = AIPlayer::spawnOnPath("Cub2","MissionGroup/Paths/Path2");
   %player.followPath("MissionGroup/Paths/Path2",-1);

   %player.mountImage(CrossbowImage,0);
   %player.setInventory(CrossbowAmmo,1000);
   return %player;
}

Ok I tried to add a second bot. Do you think this pattern of code is ok for making multiple bots ? Both the bots are working out nicely though but not sure if my technique is correct.
If I remove a bot completely do I have to reset the AImanager by AIManager.delete(); or is it ok to keep adding and removing bots from AImanager at runtime.
If I delete a bot like BotID.delete() will AImanager be able to detect it? not sure though.
#4
12/31/2006 (12:25 pm)
By just having a quick look at your code i would say the first bot wont have a crossbow :)
#5
12/31/2006 (3:15 pm)
OnReachDestination is a call back from the engine yes. The only thing it does is what you see in script. It allows for full customization. If you want the bot to continue to a new destination you must set a new destination.

I have been studying the AI code a lot lately since i am working on full blown AI. I have my pathing nearly done, so to give you an example, I have an array of Points set in a class. When OnReachDestination is called, I call my classes getNext() which returns the next destination. I then set the AI object to move to that new destination. Two lines of script. Get next, setMoveDesintation. For you, it would be a matter of setting a new destination (with setMoveDestination()) on the onReachDestination function. If that's what you want it to do.

Again to reiterate, The AiManager is a very very generic object. if you Comment
new ScriptObject(AIManager) {};
   MissionCleanup.add(AIManager);
   AIManager.think();
you've basically removed it.

Try some AI resources to get a hang of AI. Take a look at The TDN article for AI , it has some basic information that would probably be helpful.

As far as your code being ok. Not really. But its probably just the fact that im more of a dynamic guy then a hard coder. ;)

There is a resource on AI that was very helpful to me when i started. Take a look at it. It gives you easier methods of adding AI (by placing objects using the editor, instead of %player = spawn() etc). Hope i helped. happy to go more in depth if you wish.

EDIT: Oh and yea, what vincent said. the variable %player is being overwritten, not added to. If you wanted an array you could do %player1, %player2, %player@%n (or %player[%n]). There is no management of the array, so you would have to set a variable that knew the size of the array. Not very practicle in my opinion.

-jonny
#6
01/02/2007 (2:52 am)
Cool, Thanks I got a lot of bots running in cycles :)
#7
01/02/2007 (10:01 pm)
Guys how do I set target for PlayerData::onTargetEnterLOS( Obj ) Is it same as Targetnode? How do I set LOS for it.
#8
01/02/2007 (11:30 pm)
No, its not the same as targetnode.

setAimObject(obj) will set your target. setAimLocation(Point3F) will set an aim location. and setAimObject(obj,Point3F) will set aim on an object with point3F offset. onTargetEnter/ExitLOS uses your aimed object as reference on weather or not its in LOS.

Determining line of sight is actually done in the engine. it checks for static shapes, interiors and terrain only. It's not something that can't be "set" per say. You can ignore those call backs and do your own LOS checks if you wanted to allow some objects to be able to see more then others (like through walls or something).

Hope i helped!

-Jonny
#9
01/03/2007 (4:06 am)
Cool thanks again Jonny. Now I got a bot that can track player :) Also it is performing close ranged attack.