Understanding AIManager and AIPlayer
by Bruno Grieco · in Torque Game Engine · 05/17/2004 (7:07 am) · 11 replies
Guys,
I'm not sure I got the difference between the AIManager and the AIPlayer classes, when to create each.
AIManager is supposed to be created once. then every bot is supposed to be created as an AIPlayer ?
Or should every bot be created as an AIManager ?
i'm having a really strange behaviour over here. When I change some parts of my code that belong to other functions. i.e. an echo("point1"), bots disapear.
Sometimes they work perfectly, following the path ( 1 path for 2 bots ). Sometimes they both show up but only 1 bot follows the path properly. the other one doesn't receive an OnReachDestination message. Sometimes the bots are created. I see that the objects exist thru the console but there is no shape on the game.
the code below works sometimes
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();
$maxbots = 2;
for($numbots = 0;$numbots<$maxbots;$numbots++)
{
$ai[$numbots] = AIManager.spawn();
}
If i change the spawn to $ai[$numbots] = AIPlayer::spawnOnPath( "bot "@ $numbots,"MissionGroup/myPath"); which is what the AIManager.spawn does, the bots are created but aren't visible....
Could someone help me with this bot logic ?
TIA
Bruno
I'm not sure I got the difference between the AIManager and the AIPlayer classes, when to create each.
AIManager is supposed to be created once. then every bot is supposed to be created as an AIPlayer ?
Or should every bot be created as an AIManager ?
i'm having a really strange behaviour over here. When I change some parts of my code that belong to other functions. i.e. an echo("point1"), bots disapear.
Sometimes they work perfectly, following the path ( 1 path for 2 bots ). Sometimes they both show up but only 1 bot follows the path properly. the other one doesn't receive an OnReachDestination message. Sometimes the bots are created. I see that the objects exist thru the console but there is no shape on the game.
the code below works sometimes
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();
$maxbots = 2;
for($numbots = 0;$numbots<$maxbots;$numbots++)
{
$ai[$numbots] = AIManager.spawn();
}
If i change the spawn to $ai[$numbots] = AIPlayer::spawnOnPath( "bot "@ $numbots,"MissionGroup/myPath"); which is what the AIManager.spawn does, the bots are created but aren't visible....
Could someone help me with this bot logic ?
TIA
Bruno
About the author
#2
I think I managed to fix the disappearing bots problem. Looks like it had something to do with the Player datablock that myBot inherited from.
But I'm not sure.
But I still don't understand the difference between the AIManager and AIPlayer...
05/17/2004 (10:24 am)
Yep,I think I managed to fix the disappearing bots problem. Looks like it had something to do with the Player datablock that myBot inherited from.
But I'm not sure.
But I still don't understand the difference between the AIManager and AIPlayer...
#3
Sometimes all 3 bots appear and go to the destination, and sometimes one or two appear. There are times that they appear but some do not move. Every time I start the demo I get a different behavior.
This seems to work fine with the "starter.fps" though. Although I haven't tried to do "exactly" the same.
If you figure out how you fixed let me know. Meanwhile, I'll try to tackle it myself.
Nick
05/17/2004 (12:40 pm)
Hey Bruno just wanna let you know I'm having the exact same problem as you but only when using the Codesampler turorials. I have 3 bots spawning at different locations and I've set a common setMoveDestination for all three.Sometimes all 3 bots appear and go to the destination, and sometimes one or two appear. There are times that they appear but some do not move. Every time I start the demo I get a different behavior.
This seems to work fine with the "starter.fps" though. Although I haven't tried to do "exactly" the same.
If you figure out how you fixed let me know. Meanwhile, I'll try to tackle it myself.
Nick
#4
How are you setting up the AIManager and AIPlayer ?
I got the best results setting 1 AIManager object and separated AIPlayers instead of linking the AIPs to the AIMs.
Could someone please fill me in on the difference between both....
05/17/2004 (5:37 pm)
I got those bots from the codesampler tutorials also.How are you setting up the AIManager and AIPlayer ?
I got the best results setting 1 AIManager object and separated AIPlayers instead of linking the AIPs to the AIMs.
Could someone please fill me in on the difference between both....
#5
The reason we're getting this strange behavior starts at the "for" loop.
We get it if a bot happens to spawn on the same spawnsphere as another bot. We need to make some kind of mechanism that spawnspheres only get used once.
As far as the AIManager is concernced, here's how I've managed to get the best results:
And my spawn function:
There might be other ways to create bots but this is how I finally got it to work.
Now if someone could help us spawn multiple bots at different locations that'll be great.
Nick
05/18/2004 (6:24 am)
Ok, after many days of being stuck, I finally got somewhere.The reason we're getting this strange behavior starts at the "for" loop.
We get it if a bot happens to spawn on the same spawnsphere as another bot. We need to make some kind of mechanism that spawnspheres only get used once.
As far as the AIManager is concernced, here's how I've managed to get the best results:
function AIManager::spawn(%this)
{
AIPlayer::spawn("Ogre",ogrePickSpawnPoint());
AIPlayer::spawn("Troll",trollPickSpawnPoint());
AIPlayer::spawn("Goblin",goblinPickSpawnPoint());
}And my spawn function:
function AIPlayer::spawn(%name,%spawnPoint)
{
if (%name $= "Ogre") // Is this a ogre character?
{
// Create the ogre character
%player= new AIPlayer() {
dataBlock = DemoPlayer;
path = "";
};
MissionCleanup.add(%player);
%player.setShapeName(%name);
%player.setTransform(%spawnPoint);
%player.followPath("MissionGroup/Paths/Path1",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,1000);
}
if (%name $= "Troll") // Is this a troll character?
{
// Create the troll character
%player= new AIPlayer() {
etc
.
.
.
}
return %player;
}There might be other ways to create bots but this is how I finally got it to work.
Now if someone could help us spawn multiple bots at different locations that'll be great.
Nick
#6
05/18/2004 (7:15 am)
Heres how I'm currently doing it.if(containerRayCast(%spherePos, %spawnPoint, $TypeMasks::InteriorObjectType | $TypeMasks::TerrainObjectType) == 0) {
if(containerBoxEmpty($TypeMasks::InteriorObjectType | $TypeMasks::PlayerObjectType, VectorAdd(%spawnPoint, "0 0 3"), 1)) {
%AI = AIPlayer::spawn("Bot", %spawnPoint);
#7
I spawn my bots using the getTransform from the path's nodes. I spawn each one in a different node. What happens when you spawn them on the same place is that they get stuck.
05/18/2004 (7:41 am)
Nick, I don't think that would be the case for the bots not reaching the destination.I spawn my bots using the getTransform from the path's nodes. I spawn each one in a different node. What happens when you spawn them on the same place is that they get stuck.
#8
05/18/2004 (10:46 am)
There's something a little bit off in the bot code as of a few months ago (when I last worked with it). Bots don't like to reach their destination. I'm not sure why this is - I ended up avoiding the problem by ceasing my abuse of the bots and writing a class to do what I really wanted.
#9
I'm checking the getAIMove() function in AIPlayer.cc right now and the code seems to be quite self explainable :
I inserted a Con::printf function to track this and I saw that this part of the code isn't called at all.
So I guess it may be a problem of the misterious AIManager object that people don't speak about...
05/18/2004 (12:27 pm)
So should we post this as a bug Report ?I'm checking the getAIMove() function in AIPlayer.cc right now and the code seems to be quite self explainable :
if (mFabs(xDiff) < mMoveTolerance && mFabs(yDiff) < mMoveTolerance)
{
mMoveState = ModeStop;
throwCallback("onReachDestination");
}I inserted a Con::printf function to track this and I saw that this part of the code isn't called at all.
So I guess it may be a problem of the misterious AIManager object that people don't speak about...
#10
Yes, it probably is a bug.
05/18/2004 (8:33 pm)
The AIManager just tracks active bots. It's a convenience and nothing more.Yes, it probably is a bug.
#11
09/21/2007 (7:58 pm)
When you think about it, pretty much every feature is a "convienence" and nothing more. The ones that don't work are rather less convienent than those that do ....
Associate Kyle Carter