Newbie help - adding bots
by Wafaa Bilal · in Torque Game Engine · 03/03/2008 (10:30 am) · 7 replies
Hi - this is an embarrassingly simple question, but i've spent days now scouring the docs, forums, tutorials, and google, and am still mystified about how you add bots. most of the tutorials i find seem to either stop short of this ( ending on terrain editing, etc) or assume you already know how to do it and move on to more interesting and advanced things, like specific bot behaviors.
a couple of basic questions that would really clear things up for me :
- Do you have to use a SpawnSpere to create a bot? Or can it be placed directly using the world editor creator?
- If you want to have different types of bots (diff. meshes, behaviors, etc) is it correct that you would do this by creating a new .cs file for each, subclassing aiPlayer, place them all in the server/scripts directory? Or does it require c++?
- in the world editor, how do you specify which bot should show up?
- using the quickie tutorial from TDN, what does it mean if it says there is not "PlayerBody" datablock? is that a different version of aiPlayer, or could it mean aiPlayer is not found at all?
many thanks for any pointers or just links to relevant docs/tutorials.
--Team CrudeOils
( our background: experienced in C++, OpenGL, other game engines inc. Unity, Quake, OGRE, CrystalSpace ... but brand new to Torque).
a couple of basic questions that would really clear things up for me :
- Do you have to use a SpawnSpere to create a bot? Or can it be placed directly using the world editor creator?
- If you want to have different types of bots (diff. meshes, behaviors, etc) is it correct that you would do this by creating a new .cs file for each, subclassing aiPlayer, place them all in the server/scripts directory? Or does it require c++?
- in the world editor, how do you specify which bot should show up?
- using the quickie tutorial from TDN, what does it mean if it says there is not "PlayerBody" datablock? is that a different version of aiPlayer, or could it mean aiPlayer is not found at all?
many thanks for any pointers or just links to relevant docs/tutorials.
--Team CrudeOils
( our background: experienced in C++, OpenGL, other game engines inc. Unity, Quake, OGRE, CrystalSpace ... but brand new to Torque).
#2
the torque script code itself is pretty clear, it's more the World Editor that I don't understand. what i'm trying to do is have an NPC - i guess that's a "bot" - with three animation sequences. when a player enters a trigger area, the bot walks over to you and plays a sound file of a little dialogue. most of that I think is pretty well explained in the documentation and tutorials - it's just the part about adding him to the mission somewhere that's got me stumped!
Wait a sec, how about this. I want to have One and Only One instance of this particular bot. would I
(a) create him through a SpawnSphere
(b) place him in some other manner using the world editor
(c) not use the world editor at all but create him from another torque script file such as game.cs or similar?
03/03/2008 (1:34 pm)
Thanks, i feel like i'm getting closer to comprehension... :)the torque script code itself is pretty clear, it's more the World Editor that I don't understand. what i'm trying to do is have an NPC - i guess that's a "bot" - with three animation sequences. when a player enters a trigger area, the bot walks over to you and plays a sound file of a little dialogue. most of that I think is pretty well explained in the documentation and tutorials - it's just the part about adding him to the mission somewhere that's got me stumped!
Wait a sec, how about this. I want to have One and Only One instance of this particular bot. would I
(a) create him through a SpawnSphere
(b) place him in some other manner using the world editor
(c) not use the world editor at all but create him from another torque script file such as game.cs or similar?
#3
03/03/2008 (1:47 pm)
I would say (a), but that's just my opinion. I've tried it several different ways and I've found the spawn spheres work the best for me. Someone may have a different opinion though.
#4
I make a file called, say, ShawnLawson.cs, save it in server/. I'm not 100% sure what goes in that but i feel like i can figure it out by mangling various tutorial files :). but it has something to do with subclassing AIPlayer or Player or some such. e.g.
datablock TSShapeConstructor (ShawnLawsonDTS)
{
baseShape = "~/data/shapes/player/shawn.dts";
sequence0 = "~/data/shapes/player/shawn_root.dsq root";
// etc.
};
datablock PlayerData ( ShawnLawson )
{
};
Then in the World Editor I make a SpawnSphere. Do I then set the datablock of the SpawnSphere to be "ShawnLawson", and will he automatically show up?
thanks, sorry again if we sound really dense ...
03/03/2008 (2:17 pm)
Great, the fog is lifting. so let's say I want to write a bot that, for now, doesn't even do much, just stands there and runs an idle animation. I make a file called, say, ShawnLawson.cs, save it in server/. I'm not 100% sure what goes in that but i feel like i can figure it out by mangling various tutorial files :). but it has something to do with subclassing AIPlayer or Player or some such. e.g.
datablock TSShapeConstructor (ShawnLawsonDTS)
{
baseShape = "~/data/shapes/player/shawn.dts";
sequence0 = "~/data/shapes/player/shawn_root.dsq root";
// etc.
};
datablock PlayerData ( ShawnLawson )
{
};
Then in the World Editor I make a SpawnSphere. Do I then set the datablock of the SpawnSphere to be "ShawnLawson", and will he automatically show up?
thanks, sorry again if we sound really dense ...
#5
03/03/2008 (2:24 pm)
Wafaa, send me an email, the one that's in my profile and I will give you a resource that will help answer all your questions. Also, the resource I'm refering to is based on another one here, but is not entirely script based.
#6
Simple spawn function:
datablock PlayerData(ShawnLarson)
{
renderFirstPerson = false;
shapefile = "~data/shapes/player/shawn.dts";
};
datablock PlayerData(ShawnLarsonBot : ShawnLarson)
{
patrol = true;
attack = false;
};
function spawnShawnLarsonBot( %position , %botName)
{
%newBot = new AIPlayer()
{
dataBlock = ShawnLarsonBot;
};
MissionCleanup.add( %newBot );
%newBot.setName( %botName );
%newBot.setTransform( %position );
}
From here you could either console execute, or put a line of code in to do this:
spawnShawnLarsonBot(AIspawnSphere.getTransform(), "ShawnBot");
That should about do it as far as getting it into the level.
Good Luck
03/03/2008 (5:18 pm)
I think you're beginning to understand a bit better, but to get you a little bit better start, you don't want to name your spawnSphere the same thing, you'd come across errors probably (namespace issues). What I would do is call the spawnSPhere something like: AIspawnSphere Do this in the world editor, save, and then go back to the script.Simple spawn function:
datablock PlayerData(ShawnLarson)
{
renderFirstPerson = false;
shapefile = "~data/shapes/player/shawn.dts";
};
datablock PlayerData(ShawnLarsonBot : ShawnLarson)
{
patrol = true;
attack = false;
};
function spawnShawnLarsonBot( %position , %botName)
{
%newBot = new AIPlayer()
{
dataBlock = ShawnLarsonBot;
};
MissionCleanup.add( %newBot );
%newBot.setName( %botName );
%newBot.setTransform( %position );
}
From here you could either console execute, or put a line of code in to do this:
spawnShawnLarsonBot(AIspawnSphere.getTransform(), "ShawnBot");
That should about do it as far as getting it into the level.
Good Luck
#7
03/04/2008 (12:24 am)
Thanks very much for the help. Got it working, now the fun begins!
Torque Owner Doc308
Spawning Bots: In order to spawn a bot, you must give it a position, or a reference position. For instance a player is spawned at a spawn sphere because the code tells it to spawn at the position of the spawn sphere. The same CAN be done with aiPlayers, or you can create a different spawn sphere to spawn an aiPlayer, or you could create a path, and spawn it on the path and have it follow the path. In general, it's almost always better to spawn something that exists within the world (because this avoids it from falling forever and possibly crashing the engine). As far as I know, there is no current way to use the world editor to spawn a bot (besides just the object itself). You could type it in the console though...
Different types of Bots: Different .cs files are the way to go (though not absolutlely necessary). You do not have to access c++ code for this. You can also link in several bots to similiar behaviors as well. (I've got first hand experience with this).. Basically what I had done for a project was create a .cs file called botFunctions, and it would simply tells bots how to "think", "react", etc... It would use a if... else.. structure to determine different behaviors for each bot.
World Editor: I have no idea what you mean, but I'm assuming your problem lies in the bot not spawning to begin with, as there is no control in the World Editor for this.
PlayerBody: This is referencing the player datablock, some of the resources on TDN point to the player datablock for creating an aiPlayer. I'm not sure why this wouldn't be found, unless it's not setup correctly in player.cs -> best to check it to be certain. It also might not show up if it can't find the dts file.
Now, I hope that answers most of your questions. Unfortunately I don't have my code base in front of me at the moment, otherwise I'd give you an example. If you'd like, I could give you some files I've made that make bots almost seem easy to use :)
Here's my e-mail, kirksander (at) hotmail (dot) com
Good Luck