Jump to content

AI tutorial


GAN
 Share

Recommended Posts

I would recommend using a framework like BadBehavior https://github.com/BadBehavior/BadBehavior_T3D


It provides some examples and includes a behavior tree editor (which is broken currently) where you can simply edit your AI behaviors.


While a basic AI is pretty simple in Torque3D, I would recommend you using a framework it will be easier in the long run. I think adding an AI is just a single command in Torque, you can see it when you are in the NavMesh editor and add a bot for testing, but to make the bots act intelligent is some more work, thats why using a framework may be better. It depends on what you want to do. If you just want a bot randomly running around like a headless chicken, it is just one function or even one line and you don't need more, in that case you do not need a framework, but otherwise you should use one. You can write you own of course, but if you are a noob, I would not recommend that.

Link to comment
Share on other sites

Please allow me to introduce my noobiness.....


I didn't use the Chinatown set to learn about AI. I thought I could just open the simplest of maps, add a simple datablock, and have an AI guy standing there not really doing too much, but he would be there. And then I could kind of see how things are linked together. Didn't happen. And then I think, my I should just play around with Coppercube? I really want to grasp T3D. The discouraging thing with learning game engines for me and its just not T3D; I have noticed it in Unity and Cryengine: the Tutes and Docs don't match the current interface due to age differences.

Link to comment
Share on other sites

I already told you, you open the NavMesh editor and switch down in the menu on the left and you enter a feature where you can spawn an AI test player and order him around, this is just to test the NavMesh, but it is a start to give you a feeling how it works.

Link to comment
Share on other sites

the scripts/server/aiPlayer.cs is the best place to find the functions related to aiPlayers / . The Torque3d manual 3.5.1 covers aiPlayer and spawnSpere methods and things , I highly reccomend the manual its available at readthedocs.com . Study the spawnShere and aiPlayer relationship . with the spawnScript you can execute commands relative to the Bot spawned at that particular spawnSphere such as goto obj or goto path , set animation threads kind of things plus re-spawning control . The spawned object ID is saved as $spawnObject which can be used in the script . The spawn script has a limit of 255 characters . Youll need paths and waypoints and a couple of finickey little things will come with that . You might need to learn how to make a path . It involves grouping a set of waypoints into a path object . something like that .They have to be numbered . Setting a bot to a path with the argument -1 for the path marker to proceed to will result in a constant loop of the path . heres a little test path . you might have to adjust the Z values , maybe just snap to terrain .

 

 new Path(path1) {
      isLooping = "1";
      locked = "1";
      canSave = "1";
      canSaveDynamicFields = "1";
 
      new Marker() {
         seqNum = "0";
         type = "Normal";
         msToNext = "1000";
         smoothingType = "Spline";
         position = "-741.996 -541.291 233.284";
         Rotation = "1 0 0 0";
         scale = "1 1 1";
         locked = "1";
         canSave = "1";
         canSaveDynamicFields = "1";
      };
      new Marker() {
         seqNum = "1";
         type = "Normal";
         msToNext = "1000";
         smoothingType = "Spline";
         position = "-763.352 -545.388 233.079";
         Rotation = "1 0 0 0";
         scale = "1 1 1";
         locked = "1";
         canSave = "1";
         canSaveDynamicFields = "1";
      };
      new Marker() {
         seqNum = "2";
         type = "Normal";
         msToNext = "1000";
         smoothingType = "Spline";
         position = "-781.852 -530.86 234.705";
         Rotation = "1 0 0 0";
         scale = "1 1 1";
         locked = "1";
         canSave = "1";
         canSaveDynamicFields = "1";
      };
      new Marker() {
         seqNum = "3";
         type = "Normal";
         msToNext = "1000";
         smoothingType = "Spline";
         position = "-763.724 -509.504 235.157";
         Rotation = "1 0 0 0";
         scale = "1 1 1";
         locked = "1";
         canSave = "1";
         canSaveDynamicFields = "1";
      };
      new Marker() {
         seqNum = "4";
         type = "Normal";
         msToNext = "1000";
         smoothingType = "Spline";
         position = "-732.683 -525.893 233.416";
         Rotation = "1 0 0 0";
         scale = "1 1 1";
         locked = "1";
         canSave = "1";
         canSaveDynamicFields = "1";
      };
   };
 

 

Once you've spawned your bot be sure to type in objectID.dump(); in the console for a list of the available methods and things objID.dump(1); will give more details .

spawnSpheres , Paths , wayPoint Markers , Triggers , all seem pretty much fundamental . Some nifty aI oriented GUI might seem a natural progression .

Link to comment
Share on other sites

  • 2 weeks later...

I would suggest doing as Duion suggests. I did Steve Yorkshires old tutorials a few years ago and it was a huge help to me for figuring out how AI works in torque. I am still playing with different AI concepts, it is something I enjoy doing.


The Nav mesh does not "make" AIPlayers. The Nav mesh is there for AIPlayers to get around more intelligently. It is there so the AIPlayers you have will be "smarter" in choices of movement. You still have to script out how and who spawns where, then script out how the AIPlayer takes advantage of the Nav mesh (cover places, jump places, etc.). Also the Nav mesh is not the only navigation method you can use. I.E- You do not "need" to use the Nav mesh to make AIPlayers move around. Its just a really cool tool.

Link to comment
Share on other sites

  • 2 months later...
  • 1 month later...

This is a complex topic.

I highly recommend working through all of the World Editor and Scripting documents : http://www.roostertailgames.com/TorqueRef/index.html (this is my personal copy - there are others available that may be more up-to-date).

Much of the documentation is outdated but if you're willing to work through the initial learning curve it shouldn't be too hard to adapt the older examples to the newer engine.

AI isn't built in, you have to script it yourself. AIPlayer objects exist, but without some scripting they will just stand there.

Link to comment
Share on other sites

  • 2 weeks later...
  • 8 months later...

What exactly makes your documentation outdated, rlranft?

 

"Exactly?" I would say that you could diff my documentation in GitHub against the official to find out what exactly is different, but beyond that any time the engine changes or new features are added my personal copy gets farther and farther out of date.

I think http://roostertailgames.com/TorqueRef/content/documentation/Scripting/Advanced/RTSPrototype.html and http://roostertailgames.com/TorqueRef/content/documentation/Scripting/Advanced/RTSPrototype2.html will still work but I haven't tried to get these scripts functioning in anything after 3.8 so they may have broken due to engine-side changes.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...