AI Guard Unit
by Mark Holcomb · 11/27/2004 (5:18 pm) · 335 comments
Download Code File
This is my second attempt at making an AI controlled character. The first was an
AIPlayer that would follow paths. This character is a guard unit. The guard will
wait at it's post (spawn point) until it sees a target. It will then attack that
target while trying to close with it.
If the target is lost the bot will wait at the last place it saw the character and
look around for a little bit, and then it will try to return to it's post.
There is a chance the bot will get stuck trying to return, but there is a simple
routine that has the bot try to move in random directions to try and clear itself
of any obstacles between it and it's post. It's not perfect.
The thinking routine is a simple state machine - which can be expanded on to give the bot more responses and actions.
As with my first ai character, I am using a simple system that allows the designer to drop
markers in the game map that will mark where the bots will start out. When the mission is loaded, the markers are detected and bots are spawned at the marker locations. The markers are then hidden from view. (The markers can be left visible to help in map editing.)
The markers for the guards can be given a dynamic variable called respawn. (Assigned to the marker during map editing.) 'Respawn' will determine whether a bot respawns or not upon death.
The bots have an attention setting. How often they scan is determined by their attention level. The bots get more sluggish (freeing up processor time) when targets are too far away. Conversely, the bot becomes incrementally more attentive as targets come within range, and further aware as targets come into sight.
When a target is found in range and in sight the bot will shoot at the target. The firing sequence is a step of scheduled calls that call for a firing cycle, a trigger down cycle, and a firing delay to control bot rate of fire.
When a bot is attacked it will attempt to sideatep and it's field of vision is temporarily increased to a 360deg field of vision - to emulate looking around to see what happened. The bot's attention level is also set to make it think at it's fastest rate when attacked.
To use the AIGuard...the following changes need to be made.
1. Back up your original game.cs, player.cs, and your current build of Torque. To install AIGuard will require a recompile, since I have created a new class cloned by copying AIPlayer.cc and AIPlayer.h and renaming all references to AIPlayer to AIGuard.
(I did this because I wanted to be able to run both my AIPatroller and AIGuards in the same maps and did not want to have any confusion between them.)
2. Add the files AIGuard.cc and AIGuard.h to your Torque project. (In my instance I saved them to my c:\Torque\engine\game directory and then added them into my project.)
3. Recompile your project and copy your new executable to the appropriate directory for your app.
4. Copy the file AIGuard.cs into your server/scripts directory.
5. Modify game.cs to add the line
to the function onServerCreated().
6. Also in game.cs: The section for function StartGame needs to modified the following ways:
Below the lines that read:
add this:
(If you followed my previous resource you may not have any reference to AImanager. Don't fret... just look for the place in game.cs where you have
and put in
right underneath it.
7. In player.cs in the code for Armor::Damage modify the lines
to read:
*** If you followed my previous resource there should be no need to change this code.
8. Load your map - Stronghold as an example.
9. Go into the map editor. (F11) Then go into the Editor Creator (F4)
10. Under Shapes there should be a drop down called AIMarker, under that a new item called AIGuard.
11. Create a new AIGuard marker.
12. Select your marker, position it where you like and hit (F3) to modify the marker.
13. If you want to override the default respawn value - create a dynamic variable called respawn and set it's value to true or false.
14. Update your item by clicking 'APPLY'- very important and easy to miss step.
15. Save your mission and reload it.
A bot called Guard1 should appear at the spot of your marker.
If you come within range of the guard he should shoot at you and try to hunt you down.
If you get away, or when you die, he should return to his post.
I hope the resource helps other people get up and running with some AI code in their game.
And again, I'd like to thank the other members of this website whose code has been used in several places in the scripting to make this all work.
Mark H.
P.S. I've also included my AIPatrol class files with this - to install it follow the same instructions as for AIGuard, just substitute AIPatrol where AIGuard appears in the instructions. They can both be run at the same times with no problems.
P.S.S. 11/28/04 - I modified the AIPatrol.cs file to correct for a couple of typos.
P.S.S.S 12/3/04 - Added ammo and health seeking capabilities and fixed some errors. (Read posts below - or file in .zip for full details.)
This is my second attempt at making an AI controlled character. The first was an
AIPlayer that would follow paths. This character is a guard unit. The guard will
wait at it's post (spawn point) until it sees a target. It will then attack that
target while trying to close with it.
If the target is lost the bot will wait at the last place it saw the character and
look around for a little bit, and then it will try to return to it's post.
There is a chance the bot will get stuck trying to return, but there is a simple
routine that has the bot try to move in random directions to try and clear itself
of any obstacles between it and it's post. It's not perfect.
The thinking routine is a simple state machine - which can be expanded on to give the bot more responses and actions.
As with my first ai character, I am using a simple system that allows the designer to drop
markers in the game map that will mark where the bots will start out. When the mission is loaded, the markers are detected and bots are spawned at the marker locations. The markers are then hidden from view. (The markers can be left visible to help in map editing.)
The markers for the guards can be given a dynamic variable called respawn. (Assigned to the marker during map editing.) 'Respawn' will determine whether a bot respawns or not upon death.
The bots have an attention setting. How often they scan is determined by their attention level. The bots get more sluggish (freeing up processor time) when targets are too far away. Conversely, the bot becomes incrementally more attentive as targets come within range, and further aware as targets come into sight.
When a target is found in range and in sight the bot will shoot at the target. The firing sequence is a step of scheduled calls that call for a firing cycle, a trigger down cycle, and a firing delay to control bot rate of fire.
When a bot is attacked it will attempt to sideatep and it's field of vision is temporarily increased to a 360deg field of vision - to emulate looking around to see what happened. The bot's attention level is also set to make it think at it's fastest rate when attacked.
To use the AIGuard...the following changes need to be made.
1. Back up your original game.cs, player.cs, and your current build of Torque. To install AIGuard will require a recompile, since I have created a new class cloned by copying AIPlayer.cc and AIPlayer.h and renaming all references to AIPlayer to AIGuard.
(I did this because I wanted to be able to run both my AIPatroller and AIGuards in the same maps and did not want to have any confusion between them.)
2. Add the files AIGuard.cc and AIGuard.h to your Torque project. (In my instance I saved them to my c:\Torque\engine\game directory and then added them into my project.)
3. Recompile your project and copy your new executable to the appropriate directory for your app.
4. Copy the file AIGuard.cs into your server/scripts directory.
5. Modify game.cs to add the line
exec("./aiGuard.cs"); to the function onServerCreated().
6. Also in game.cs: The section for function StartGame needs to modified the following ways:
Below the lines that read:
// Start the AIManager
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();add this:
AIGuard::LoadEntities();
(If you followed my previous resource you may not have any reference to AImanager. Don't fret... just look for the place in game.cs where you have
AIPlayer::LoadEntities
and put in
AIGuard::LoadEntities();
right underneath it.
7. In player.cs in the code for Armor::Damage modify the lines
// Deal with client callbacks here because we don't have this
// information in the onDamage or onDisable methods
%client = %obj.client;
%sourceClient = %sourceObject ? %sourceObject.client : 0;
if (%obj.getState() $= "Dead")
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);to read:
// Deal with client callbacks here because we don't have this
// information in the onDamage or onDisable methods
%client = %obj.client;
%sourceClient = %sourceObject ? %sourceObject.client : 0; if (%obj.isbot == true)
{
%obj.attentionlevel=1;
%obj.enhancefov(%obj);
}
if (%obj.getState() $= "Dead")
{
if (%obj.isbot == true)
{
if (%obj.respawn == true)
{
%obj.delaybeforerespawn(%obj.botname, %obj.markerpos, %obj.marker);
%this.player=0;
}
}
else
{
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}
}*** If you followed my previous resource there should be no need to change this code.
8. Load your map - Stronghold as an example.
9. Go into the map editor. (F11) Then go into the Editor Creator (F4)
10. Under Shapes there should be a drop down called AIMarker, under that a new item called AIGuard.
11. Create a new AIGuard marker.
12. Select your marker, position it where you like and hit (F3) to modify the marker.
13. If you want to override the default respawn value - create a dynamic variable called respawn and set it's value to true or false.
14. Update your item by clicking 'APPLY'- very important and easy to miss step.
15. Save your mission and reload it.
A bot called Guard1 should appear at the spot of your marker.
If you come within range of the guard he should shoot at you and try to hunt you down.
If you get away, or when you die, he should return to his post.
I hope the resource helps other people get up and running with some AI code in their game.
And again, I'd like to thank the other members of this website whose code has been used in several places in the scripting to make this all work.
Mark H.
P.S. I've also included my AIPatrol class files with this - to install it follow the same instructions as for AIGuard, just substitute AIPatrol where AIGuard appears in the instructions. They can both be run at the same times with no problems.
P.S.S. 11/28/04 - I modified the AIPatrol.cs file to correct for a couple of typos.
P.S.S.S 12/3/04 - Added ammo and health seeking capabilities and fixed some errors. (Read posts below - or file in .zip for full details.)
#262
I have the same issue, one part of the answer is that torque script is slower than C++ obviously. My suggestion is that you try to simplify the AI script as there must be some features in AI Guard Unit that you don't need i.e. looking for amo. You might want to try slowing down the rate and distance of detection too.
I have to do it for my project, if I can optimise the script enough to keep the frame rate acceptable I will post the modified files here.
11/04/2007 (9:04 am)
Jesse :I have the same issue, one part of the answer is that torque script is slower than C++ obviously. My suggestion is that you try to simplify the AI script as there must be some features in AI Guard Unit that you don't need i.e. looking for amo. You might want to try slowing down the rate and distance of detection too.
I have to do it for my project, if I can optimise the script enough to keep the frame rate acceptable I will post the modified files here.
#263
I have 20 bots running around my own mission at this point and I have no lag or slow down issues, so I don't think it's just a Torque Script issue.
11/04/2007 (10:24 am)
@Jesse P & Maruejol Cedric: I have the other AiGuard resource from Ken Finney's book and that is all script and I'm not having any issues with performance. While I believe Finney's was based on this one, it was the only one I could get working. I have 20 bots running around my own mission at this point and I have no lag or slow down issues, so I don't think it's just a Torque Script issue.
#264
11/04/2007 (12:50 pm)
ok thanks for the feedback Chris, I am wondering now ;o) how many bots can chase you at the same time whithout experiencing any lag ??
#265
I have had several bots attack me without any lag though( I die pretty quickly though as well). I'd say up to 5, but I have them spaced out throughout the mission(I like big missions). As I could never get this resource working, I really can't compare the two, unless you can tell me where to put the includes for this resouce :) (Mark Holocomb never put down where to put the includes and I have tried implementing it, but if you look at my other post in this thread you'll see where I'm at.)
11/04/2007 (1:00 pm)
I really haven't tried running through the mission to even try that. In fact, I'm stuck at the moment trying to implement a second NPC type with Finney's resource.I have had several bots attack me without any lag though( I die pretty quickly though as well). I'd say up to 5, but I have them spaced out throughout the mission(I like big missions). As I could never get this resource working, I really can't compare the two, unless you can tell me where to put the includes for this resouce :) (Mark Holocomb never put down where to put the includes and I have tried implementing it, but if you look at my other post in this thread you'll see where I'm at.)
#266
I have not touched this code in a very long time and I can't really address your specific problems directly. But...
The include files go in your {Torque}\engine\game folder and you have to add them in with your compiler's methodology to get them added to the project files and then recompile the code. The {Torque} represents your folder where your source files may be... on my machine it's C:\Torque\TGE_1_5_2\engine\game yours will probably vary.
I have not tried implementing Ken Finney's code from his book, but I would not be surprised if his isn't a little more refined than mine. Mine was based on some concepts and ideas from his first edition book, so it's not a surprise to see some strong similarities.
I have also posted another resource for navigation and path finding. It has been expanded on by a couple of others but it helps create a more robust toolset for AI NPC's to use to move around and such.
It can be found here:
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6889
Hopefully some of this helps. If not repost with your questions and I'll try to answer them as best I can.
11/04/2007 (8:12 pm)
A few quick comments.I have not touched this code in a very long time and I can't really address your specific problems directly. But...
The include files go in your {Torque}\engine\game folder and you have to add them in with your compiler's methodology to get them added to the project files and then recompile the code. The {Torque} represents your folder where your source files may be... on my machine it's C:\Torque\TGE_1_5_2\engine\game yours will probably vary.
I have not tried implementing Ken Finney's code from his book, but I would not be surprised if his isn't a little more refined than mine. Mine was based on some concepts and ideas from his first edition book, so it's not a surprise to see some strong similarities.
I have also posted another resource for navigation and path finding. It has been expanded on by a couple of others but it helps create a more robust toolset for AI NPC's to use to move around and such.
It can be found here:
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6889
Hopefully some of this helps. If not repost with your questions and I'll try to answer them as best I can.
#267
I have the C++ code in the right folder, it's just where to put the includes is my problem. As you kind of guessed above (A long time ago) there was a certain place to put those files. One other person was having the same problem I was and he found two places for the includes and it worked out for him. I found five of the files that included what you guessed at, so I'm not exactly sure where to place the includes as putting it everywhere will give you errors.
Anyway, thanks for your comments. As always they are appreciated.
11/04/2007 (8:18 pm)
Thanks Mark,I have the C++ code in the right folder, it's just where to put the includes is my problem. As you kind of guessed above (A long time ago) there was a certain place to put those files. One other person was having the same problem I was and he found two places for the includes and it worked out for him. I found five of the files that included what you guessed at, so I'm not exactly sure where to place the includes as putting it everywhere will give you errors.
Anyway, thanks for your comments. As always they are appreciated.
#268
12/06/2007 (6:20 pm)
Hey Mark, for performance reasons I went out and bought Ken Finney's book and put his AIGuard example in my project, I've been struggling with it for over a month now and can't get it to work right, he keeps loosing the player and never re-detects him, I am not much of a coder at all and need an experts help, I've posted a half dozen messages around the forums for the past month about it but have not been able to resolve it so I figure I'd message the expert about AI. I really would like you to take a look at it if you have the time, I'd like to email it to you and see if you can figure out why it is loosing the player so often. It is holding my entire project up. Thank you in advance, please email me at jpetrilla@mail.com I would really appreciate it
#269
Unhandled exception at 0x00b58f16 in insecticide.exe: 0XC0000005:
Access violation reading location 0x0000000c.
In Visual Studio, it points to line 40 of tsMesh.h, which is:
U32 size() const ( return sz==0; )
The two things I can think of that are causing me problems are this: in order to keep a cleaner directory, I moved the starter.fps folder (along with common and creator) out of the example folder, and placed them into a new folder. I deleted example, renamed starter.fps to the name of our project (hence insecticide.exe above) and stripped out all of the unnecessary assets.
The other issue, is when I recompiled Torque the first time to get an executable with the name of our project, I edited the Linker section of the project to output the .exe into the new folder I had created. I'm no programmer, so I basically did the bare minimum I could find to get a file named "insecticide.exe" into the new folder I had created. In conjunction with this, when I added the four files (aiGuard and aiPatrol) to the engine/game directory, then added them into the project itself, I right clicked on the project, went to Add -> Add Existing instead of Add New.
However, I was also unable to get this to work in a fresh install of Torque 1.5.2, and (as far as I could tell) I was still getting the same error. Can anyone see what I've done wrong?
12/30/2007 (8:28 pm)
I am having an issue trying to get this resource working. I have followed all of the steps, and I am able to get to the level select UI in Torque. However, when I chose a level (a blank level I created for my class to build off of,) I get an error with lots of lovely hex code before the datablocks even load. When I debug the project in VS2k5, I get the following error:Unhandled exception at 0x00b58f16 in insecticide.exe: 0XC0000005:
Access violation reading location 0x0000000c.
In Visual Studio, it points to line 40 of tsMesh.h, which is:
U32 size() const ( return sz==0; )
The two things I can think of that are causing me problems are this: in order to keep a cleaner directory, I moved the starter.fps folder (along with common and creator) out of the example folder, and placed them into a new folder. I deleted example, renamed starter.fps to the name of our project (hence insecticide.exe above) and stripped out all of the unnecessary assets.
The other issue, is when I recompiled Torque the first time to get an executable with the name of our project, I edited the Linker section of the project to output the .exe into the new folder I had created. I'm no programmer, so I basically did the bare minimum I could find to get a file named "insecticide.exe" into the new folder I had created. In conjunction with this, when I added the four files (aiGuard and aiPatrol) to the engine/game directory, then added them into the project itself, I right clicked on the project, went to Add -> Add Existing instead of Add New.
However, I was also unable to get this to work in a fresh install of Torque 1.5.2, and (as far as I could tell) I was still getting the same error. Can anyone see what I've done wrong?
#270
'2. Add the files AIGuard.cc and AIGuard.h to your Torque project. (In my instance I saved them to my
c:\Torque\engine\game directory and then added them into my project.)'
I added AIGuard.cc and AIGuard.h in C:\Torque\TGE_1_5_2\engine\game. is that the correct place or do i need to make a new folder in the game directory?
'3. Recompile your project and copy your new executable to the appropriate directory for your app.'
what does this actually mean? what is the project?
I have visual c++ 2005 could someone please tell me how to recompile these files step by step.
When i do load the starter.fps and the map stronghold kork is running around but no aiGuard but in editor the ai marker is there but not the actual guard bot.
in console it says
Loading Guard entities...
starter.fps/server/scripts/aiGuard.cs (345): Unable to intantiate non-conobject class AIGuard
starter.fps/server/scripts.aiGuard.cs (361): Unable to find object: '0' attempting to call function 'EquiBot'
starter.fps/server/scripts.aiGuard.cs (363): Unable to find object: '0' attempting to call function 'setShapeName'
starter.fps/server/scripts.aiGuard.cs (365): Unable to find object: '0' attempting to call function 'setTransform'
starter.fps/server/scripts.aiGuard.cs (367): Unable to find object: '0' attempting to call function 'schedule'
Hiding Guard markers...
any help will be appreciated
01/08/2008 (5:42 pm)
I have added the aiGuard marker in the map but when i reload it Guard1 doesnt respawn. I have followed the steps but I had trouble on how to recompile the aiGuard.cc and aiGuard.h I think I havent recompiled it properly.'2. Add the files AIGuard.cc and AIGuard.h to your Torque project. (In my instance I saved them to my
c:\Torque\engine\game directory and then added them into my project.)'
I added AIGuard.cc and AIGuard.h in C:\Torque\TGE_1_5_2\engine\game. is that the correct place or do i need to make a new folder in the game directory?
'3. Recompile your project and copy your new executable to the appropriate directory for your app.'
what does this actually mean? what is the project?
I have visual c++ 2005 could someone please tell me how to recompile these files step by step.
When i do load the starter.fps and the map stronghold kork is running around but no aiGuard but in editor the ai marker is there but not the actual guard bot.
in console it says
Loading Guard entities...
starter.fps/server/scripts/aiGuard.cs (345): Unable to intantiate non-conobject class AIGuard
starter.fps/server/scripts.aiGuard.cs (361): Unable to find object: '0' attempting to call function 'EquiBot'
starter.fps/server/scripts.aiGuard.cs (363): Unable to find object: '0' attempting to call function 'setShapeName'
starter.fps/server/scripts.aiGuard.cs (365): Unable to find object: '0' attempting to call function 'setTransform'
starter.fps/server/scripts.aiGuard.cs (367): Unable to find object: '0' attempting to call function 'schedule'
Hiding Guard markers...
any help will be appreciated
#271
I'm working with mech player models and their scale is several times larger than the Kork model. If I scale them down to the size of the Kork model, then the AI see them properly, but if I leave them larger, then they only seem to detect them when the players back is to them. Also if I exaggerate the players bounding box to a size that is not reasonable to work with (because it would restrict movement under things) again they will detect the player.
The obvious answer is to rescale everything, but there ought to be another solution, but I certainly haven't found it yet.
01/11/2008 (5:12 pm)
Has anyone had this issue, my AI Guards only attack when the player's back is turned? I know exactly what it is, or at least related to, but I'm not sure how to fix it. I'm working with mech player models and their scale is several times larger than the Kork model. If I scale them down to the size of the Kork model, then the AI see them properly, but if I leave them larger, then they only seem to detect them when the players back is to them. Also if I exaggerate the players bounding box to a size that is not reasonable to work with (because it would restrict movement under things) again they will detect the player.
The obvious answer is to rescale everything, but there ought to be another solution, but I certainly haven't found it yet.
#272
Surely there's an scale issue. I scaled down the player to half then guards could not see the player.
The following code snip is what I done:
I ran it on TGEA, it could be integrated smoothly. :-)
Thank you for the great resource.
01/17/2008 (8:11 pm)
@AlanSurely there's an scale issue. I scaled down the player to half then guards could not see the player.
The following code snip is what I done:
%player = new Player() {
dataBlock = PlayerBody;
client = %this;
scale = "0.5 0.5 0.5";
};I ran it on TGEA, it could be integrated smoothly. :-)
Thank you for the great resource.
#273
Any help will be appreciated
01/19/2008 (12:29 pm)
Doesn't anyone have an answer to my previous post? (3 posts up)Any help will be appreciated
#274
It kind of looks like you added the files to your project directory, but didn't add them to the project. The reason I suspect that is that the error you are getting indicates that Torque doesn't think the non-conobject class AIGuard exists. To make sure you've added these files (aiguard.cc, aiguard.h) to your build, open up your "Torque SDK.sln" and make sure your working with the Torque Demo:

Then select the "Project" drop down at the top (I'm using VS 2003 here, but it should be pretty much the same in Express 2005) and then select add existing item:

From the next pop up dialog select the files you need to add to the project:

Then select open. At that point they should be added to you build. Do a Re-build of the Torque Demo just to make sure and that should do it. If you've already done this, then I'm not sure what is happening.
-Alan
BTW, don't mind that it says Torque Game Engine Advanced in the header, I was just using that project for illustrative purposes.
.
01/19/2008 (4:19 pm)
@Mohammad,It kind of looks like you added the files to your project directory, but didn't add them to the project. The reason I suspect that is that the error you are getting indicates that Torque doesn't think the non-conobject class AIGuard exists. To make sure you've added these files (aiguard.cc, aiguard.h) to your build, open up your "Torque SDK.sln" and make sure your working with the Torque Demo:

Then select the "Project" drop down at the top (I'm using VS 2003 here, but it should be pretty much the same in Express 2005) and then select add existing item:

From the next pop up dialog select the files you need to add to the project:

Then select open. At that point they should be added to you build. Do a Re-build of the Torque Demo just to make sure and that should do it. If you've already done this, then I'm not sure what is happening.
-Alan
BTW, don't mind that it says Torque Game Engine Advanced in the header, I was just using that project for illustrative purposes.
.
#275
Loading Guard entities...
starter.fps/server/scripts/aiGuard.cs (345): Unable to intantiate non-conobject class AIGuard
Set::add: Object "0" doesnt exist
starter.fps/server/scripts.aiGuard.cs (361): Unable to find object: '0' attempting to call function 'EquiBot'
starter.fps/server/scripts.aiGuard.cs (363): Unable to find object: '0' attempting to call function 'setShapeName'
starter.fps/server/scripts.aiGuard.cs (365): Unable to find object: '0' attempting to call function 'setTransform'
starter.fps/server/scripts.aiGuard.cs (367): Unable to find object: '0' attempting to call function 'schedule'
Hiding Guard markers...
I had to put "$AI_GUARD_ENABLED = false;" from false to true that is the only thing I changed from AiGuard.cs
Am I doing something really wrong. I have been trying to sort this problem out for a few weeks.
Does anyone have any idea whats going on.
Any help will be appreciated.
01/20/2008 (2:11 pm)
Thanks for your guide to compile. I didn't do that before and I know that it did compile properly this time because I rebuild the whole project and had no errors. But I still get the same error in console except theres another line which came up now and didn't before "Set::add: Object "0" doesnt exist".Loading Guard entities...
starter.fps/server/scripts/aiGuard.cs (345): Unable to intantiate non-conobject class AIGuard
Set::add: Object "0" doesnt exist
starter.fps/server/scripts.aiGuard.cs (361): Unable to find object: '0' attempting to call function 'EquiBot'
starter.fps/server/scripts.aiGuard.cs (363): Unable to find object: '0' attempting to call function 'setShapeName'
starter.fps/server/scripts.aiGuard.cs (365): Unable to find object: '0' attempting to call function 'setTransform'
starter.fps/server/scripts.aiGuard.cs (367): Unable to find object: '0' attempting to call function 'schedule'
Hiding Guard markers...
I had to put "$AI_GUARD_ENABLED = false;" from false to true that is the only thing I changed from AiGuard.cs
Am I doing something really wrong. I have been trying to sort this problem out for a few weeks.
Does anyone have any idea whats going on.
Any help will be appreciated.
#276
Did you by chance change the player datablock in the player.cs file to something else from the default "datablock PlayerData(PlayerBody)"?
The AIGuard.cs uses the default PlayerBody as it's ai player body and if you changed that, you need to change it in the AIGuard.cs towards the top (around line 78 or so).
Honestly I've had that error in the past, and I think it's related to non-matching names of datablocks, but I cant remember what exactly causes it. Hopefully someone who knows explicitly the reason for error will chime in here.
01/20/2008 (2:30 pm)
@Mohammad,Did you by chance change the player datablock in the player.cs file to something else from the default "datablock PlayerData(PlayerBody)"?
The AIGuard.cs uses the default PlayerBody as it's ai player body and if you changed that, you need to change it in the AIGuard.cs towards the top (around line 78 or so).
Honestly I've had that error in the past, and I think it's related to non-matching names of datablocks, but I cant remember what exactly causes it. Hopefully someone who knows explicitly the reason for error will chime in here.
#277
Player.cs - datablock PlayerData(PlayerBody)
AiGuard.cs - datablock PlayerData(GuardPlayer : PlayerBody)
Is the "GuardPlayer" meant to be there?
01/20/2008 (3:04 pm)
I didn't change that from player.cs but in aiguard .cs its a bit different:Player.cs - datablock PlayerData(PlayerBody)
AiGuard.cs - datablock PlayerData(GuardPlayer : PlayerBody)
Is the "GuardPlayer" meant to be there?
#278
I really think it's some kind of naming issue, because I remember now having that particular error when I was working on player selection scripts and Torque wasn't getting passed the correct name to spawn the right player.
You for sure also added the "AIGuard::LoadEntities();" (without the quotes) into your game.cs script? Just checking and trying to guess why it doesn't seem to recognize you aiguard.
01/20/2008 (3:29 pm)
Yes, that's correct. That all looks fine. hmm...I'll keep thinking about it. I really think it's some kind of naming issue, because I remember now having that particular error when I was working on player selection scripts and Torque wasn't getting passed the correct name to spawn the right player.
You for sure also added the "AIGuard::LoadEntities();" (without the quotes) into your game.cs script? Just checking and trying to guess why it doesn't seem to recognize you aiguard.
#279
On your previous post about compiling when you said:
"open up your "Torque SDK.sln" and make sure your working with the Torque Demo:"
Did you mean to open up visual c++ and work with torque demo there to add the aiguard.cc, aiguard.h?
Because I opened up Visual C++ and opened torque demo to add the two files.
01/22/2008 (7:19 am)
@ Alan James,On your previous post about compiling when you said:
"open up your "Torque SDK.sln" and make sure your working with the Torque Demo:"
Did you mean to open up visual c++ and work with torque demo there to add the aiguard.cc, aiguard.h?
Because I opened up Visual C++ and opened torque demo to add the two files.
#280
01/22/2008 (3:04 pm)
Yes, I usually start my project by just double clicking the Torque SDK.sln, but it sounds like you are doing it right, just going at it from another direction. 
Torque Owner Jesse P