Game Development Community

Make aiPlayer aim at me

by gamer · in Torque Game Engine · 06/06/2006 (2:33 pm) · 5 replies

I want to make the aiPlayer aim at me when the fps starts, not sure where would be a good entry point to place my code at, tried in AIManager::spawn, however the ServerConnection is not created it yet at that point. any idea?
thanks
function AIManager::spawn(%this)
{

   %player = AIPlayer::spawnOnPath("Target","MissionGroup/AIPath/Path");
  %player.setAimObject(ServerConnection.getControlObject()); //incorrect

   return %player;
}

#1
06/06/2006 (4:09 pm)
Write a function in the AIManager which aims [all] AIPlayers at an object,
and on the server side you should wait until the client connects and is spawned,
and then call that AIManager function with the newly-spawned player.
#2
06/06/2006 (4:39 pm)
Thanks, then I need to keep track of all the AIPlayers in AIManager, i am not sure how to declare a variable in AIManager scope. I am a little confused on AIManager, does it have a corresponding class in the engine? or is it just a namespace? and also I cant' seem to find who's invoking its method AIManager:think().
#3
06/06/2006 (4:46 pm)
It's in game.cs: (at least it is on mine)

// Responsible for managing all bots in general.
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();


and yeah, you'll need to keep track of all the bots in the AIManager.
.. i did this via just like %this.bots[%this.numBots],
but in retrospect i really wish i'd initially gone with a simset instead.

so i'd expand the above to something like:
// Responsible for managing all bots in general.
   new ScriptObject(AIManager) {};
   MissionCleanup.add(AIManager);
   AIManager.bots = new SimSet();
   MissionCleanup.add(AIManager.bots);
   AIManager.think();

and then used %this.bots.add() and such.

- note i think you'll need a sim*set* there, not a sim*group*.

i haven't tried it tho. if you do can you post how it goes ?
#4
06/06/2006 (6:54 pm)
I'll try it. one thing about new ScriptObject(AIManager){
}, does this creates an object named AIManager? should I do something like
new ScriptObject(AIManager){
class="AIManager";
}
to give it a class name? or does torque not care.
#5
06/06/2006 (7:56 pm)
I'm a little shaky on torque namespaces & classes and such,
but i can tell you that there's no need to include class="AIManager";.

stock TGE doesn't do it, so pretty much you don't need to.

when you go new ScriptObject(AIManager) {};,
a new object of class ScriptObject is created,
but you can write methods/functions for that specific object ala:
function AIManager::fooFunc(%this)
{
   echo(%this.getClassName());
}
which i think will result in "ScriptObject".

So it's a little weird.

If you're planning on having more than one AIManager,
you should probably look into the whole class-versus-instance thing,
but if not, you're good-to-go with the stock example.

See for example the methods belonging to PlayGui:
it's just an Instance of TSGuiCtrl (or whatever),
but you still write methods for it as function PlayGui::OnMouseDown(%this) or what-have-you.

hopefully this works out for you.

Also,
your original post didn't really indicate that you wanted more than one AI Player,
which if you're sure you'll only have one then you could just assign it to a global variable like $TheOneAndOnlyAIPlayer.