Game Development Community

Multiple AI Bot types

by Jonathan Rose · in Torque Game Engine · 12/09/2005 (7:39 pm) · 10 replies

Yeah, I know this problem is probably just something stupid, but... well, I'm having a bit of trouble getting AI bots to use different players at the same time. I can get either AI bot to load depending on the order of execution of the script, so I have a feeling that I've made some idiotic conflict in the AI scripts... so if someone would help me out with this, it'd be greatly appreciated. I'm working off of a tutorial that I found... somewhere. Also, I'm working off of tutorial.base. I'd post up the log, but it didn't show me anything out of the ordinary.


First AI script:
bot.cs

Second AI script:
wheelieAI.cs

First Player Script:
playershadow.cs


Second Player Script:
wheelie.cs

It's probably in the AI scripts, but hey... I could be wrong... so I included the player scripts.

#1
12/10/2005 (6:45 am)
Not the best way to do it but you could just duplicate the bot head code and rename everything.
#2
12/10/2005 (7:13 am)
Just to let you know, the reason only one works at a time is cos you have functions in wheelieAi.cs & bot.cs that are named identically.

Example:

function AIPlayer::spawn( %name, %spawnPoint )

This function appears in both scripts, functions cannot be named the same.

If bot.cs had...

function AIPlayer::spawn( %name, %spawnPoint )

& wheelie.cs had...

function AIPlayer2::spawn( %name, %spawnPoint )

...not a problem.
#3
12/10/2005 (7:50 am)
Doesn't it always have to be AIPlayer? I thought this was important to inherate built in methods from Torque otherwise they wouldn't think / fire etc...
#4
12/10/2005 (8:20 am)
That's why you have to duplicate headcode :)
#5
12/10/2005 (11:42 am)
EDIT:
Surely there is a better way of doing this than duplicating the AIPlayer.cc into AIPlayer2.cc and then renaming everything isn't there? I would have thought that you could have the AIPlayer controlling many different types of players...
#6
12/10/2005 (1:29 pm)
I am working on an elaborate resource which separates AI from the avatar whose thought process it is meant to represent. This is probably the better way to modularize this. The people aren't different -- their thinking is. A good design should also permit a given avatar to switch from one AI to another.

Just a suggestion.

tone
#7
12/10/2005 (1:44 pm)
You do not need to duplicate the AiPlayer class. In this case, you can simple prefix all the functions for the "Wheelie AI" with Wheeled and be done with it.

Modified Tim's example:

If bot.cs had...

function AIPlayer::spawn( %name, %spawnPoint )

& wheelie.cs had...

function AIPlayer::wheeledSpawn( %name, %spawnPoint )

I'm really over simplifying this rather than being helpfull and explaining to you how the whole thing works, but maybe this will help you to figure it out on your own.

Edit: If you're serious about AI then you should stop scripting right now and take it in to the source. Creating some sort of path finding system is usualy a good start(A* seems to be a favorite around here).
#8
12/10/2005 (2:01 pm)
Well, I'm mostly just playing around with the scripting right now to get the bots set up. I only plan on doing really simple AI things for now though. But thanks, that pretty much solves my problem :P
#9
12/10/2005 (2:18 pm)
The only functions that need to have a specific name are those being called by the script ex. oncollision, onadd, onreachdestination. for these you could have

function AIPlayer::onadd( %obj){
if (%obj.type $= "wheelie"){
etc.....
}
if (%obj.type $= "default"){
etc...
}
}
of course you would have to assign the AIplayers types when you spawned them which would look like

%obj.type = "wheelie";
for the wheelie spawn
and
%obj.type = "default";
for the normal spawn then you can have one function and do two different things
#10
12/11/2005 (8:53 pm)
Do the functions look for the className when calling: oncollision, onadd, onreachdestination?

Is this something that can be fixed by changing the className? Or maybe hacking the code to use a different className if provided by a variable or something?

I could see this being vary useful for other types of objects.