Game Development Community

AI spawn and pathing in T3D

by Donald Teal · in Torque 3D Professional · 10/05/2009 (11:19 pm) · 26 replies

Ok I am trying to get my basic AI working. I have made a path to follow and it shows up fine. Nothing seems to happen. What other things need to be done to get the model to spawn and start patrolling the path?
Page «Previous 1 2
#1
10/05/2009 (11:40 pm)
hmm sounds like you should look into the Universal AI kit or AIgaurd or patrol maybe (which by now should be a standard in t3d.. really are we all still using aiplayer?)
#2
10/05/2009 (11:42 pm)
Check out the spawn function at the end of the stock AIPlayer.cs, it shows how to set up a path script.
#3
10/06/2009 (1:28 am)
Look inside of "scripts/server/gameCore.cs" at function GameCore::startGame() and also at function GameCore::endGame(), find the commented lines for the AIManager ScriptObject and uncomment them. If your paths are set up correctly (as per the code) when you next start your mission the bot will be following your path.
#4
10/06/2009 (1:48 pm)
OK I still can't get the bot to spawn and follow the path. Any other info you can give me or a basic walkthru you can point me to. I am haveing trouble wrapping my head around this and want to learn it instead of just purchasing a resource to do it for me. although I will probly still buy a resource I want to learn the mechanics.
#5
10/06/2009 (1:55 pm)
With AImanager on in gamecore - bottom of AIplayer is:

%player = AIPlayer::spawnOnPath("Shootme", "MissionGroup/Paths/Path1");

that's an AI called Shootme, spawning on a path called Path1 in a simgroup called Paths. Do you have this set up in your mission?
#6
10/06/2009 (2:06 pm)
  • Create a simgroup, call it "Paths".
  • Right-click this simgroup and select "Add new objects here".
  • i167.photobucket.com/albums/u143/heretek/torque/screenshot_001-00000-10-1.png
    Once your Simgroup is selected you will see it's folder/tree icon change and have an indicator that this is the active simgroup that new objects will be created in.
    i167.photobucket.com/albums/u143/heretek/torque/screenshot_002-00000-5-1.png
  • Create a path object, name it "Path1".
  • Right-click this object (it acts just like another simgroup) and select "Add new objects here".
  • Create a marker.
  • Create more markers.

  • As you do this each successive marker is incremented automatically (eg, the seqNum field). Save the level and when you reload it (after re-enabling the AIManager as noted above) a bot will spawn on your newly created path.
    #7
    10/06/2009 (3:08 pm)
    Thanks ever so much. what I was doing wrong was not first creating the simgroup to put the path object in.
    #8
    10/06/2009 (4:02 pm)
    I guess making them attack is a little more complex than just mounting a weapon to the bot.
    #9
    10/06/2009 (4:12 pm)
    lol
    #10
    10/06/2009 (5:06 pm)
    lol indeed.

    Ai can only do what they are told to - or can only work within the parameters that they have defined --- which is the same thing.

    There are a couple of resources available. Search for AIguard or KillerKork, and try to implement them.
    #12
    10/06/2009 (5:31 pm)
    KillerKork can be a lot of fun :D if you're looking for deathmatch style bots and the Improved AIGuard resource is a good starter resource for learning how to setup patrolling/roaming and stationary/guard bot behavior. Both of these resouces are script only and can pretty much drop straight into Torque3D (KillerKork may take a little of fiddling). You'll learn the basics of AI sight/senses and how to make your bots think/decide, as well as how to make them shoot at something.

    For more serious AI behavior as well as path-finding (not the same as path following) you would want/need to move over into C++ code -- but you'll probably want to stick with the basics first and then study up on the more advanced AI stuff.

    AI is really easy to write, the hard part is making it believable and not seem dumb -- and that's where you'll spend countless hours researching the subject...
    #13
    10/06/2009 (8:09 pm)
    thanks again for all the info. will be looking into the resources you guys pointed out.
    #14
    10/25/2009 (9:51 pm)
    I'm following this tute and have a couple of questions.
    How do I set the character/AI to use? I changed the name in %player = AIPlayer::spawnOnPath("Shootme", "MissionGroup/Paths/Path1"); but the AI shows up as the same character as the player. I noticed this after changing the player back to Gideon in player.cs. I had him as the AI at first when trying to get the animations etc all working.

    Then I accidentally moved my player spawn point down to the path sim group and suddenly the path showed up as green triangles. (I may have moved it accidentally or it did it on its own, not sure)
    Anyway, there's no mention above of dropping a spawn point for the AI or how to do it.

    I gotta say tho, this is awesome! I've been chasing myself around and blasting my own a** off for quite some time!

    My guess is I need to edit something here but I don't even have a file called demo player...

    function AIPlayer::spawn(%name,%spawnPoint)
    {
    // Create the demo player object
    %player = new AiPlayer()
    {
    dataBlock = DemoPlayer;
    path = "";
    };
    MissionCleanup.add(%player);
    %player.setShapeName(%name);
    %player.setTransform(%spawnPoint);
    return %player;
    }

    Any help would be appreciated.

    Scot
    #15
    10/28/2009 (3:56 pm)
    I bought the Improved AIGuard pack and have a few more questions. I'm trying to set it up to be able to have multiple different AI in multiple missions. I need to be able to set-up unique monsters that do different things and have different animations and I can't seem to find a 'complete' tutorial on how to add new AI/characters for a multiplayer game anywhere. The AIGuard pack isn't fully T3D ready and isn't meant for multi-player either.

    1. Why is there a file called aiPlayer.cs in the datablocks directory and also one in the scripts/server directory?
    2. If I want to use a model named monster1.dts I understand that I create a directory called monster1 under art/shapes/actors and add the dts file for him, the texture file and sequences. I copied gideon.cs and changed the name to monster1.cs and changed the animation seq lines to match the monsters seqs. And he works in game. So...then what?

    I've been at this for 3 or 4 days now and I'm still not seeing what might look obvious to you.

    As usual, any help is appreciated!
    #16
    10/28/2009 (5:30 pm)
    have you tried asking in the Improved AIGuard pack thread. this thread was about the simple ai included in T3D. I have not tried the Improved AIGuard pack so dont have any knowledge on how it works.
    #17
    10/28/2009 (5:40 pm)
    I did ask there, no reply so far.
    #18
    10/28/2009 (9:13 pm)
    Has anyone had success producing paths from script ?

    Is this even possible ?
    #19
    10/28/2009 (9:45 pm)
    @scot
    Going back to post14... and without looking at the scripts -

    Demoplayer = go look under art/datablocks for AIplayer. The playerdata should say playerdata(demoplayer : defaultplayerdata) or words to that effect.

    That means that demoplayer is referencing all it's info from the defaultplayerdata ===== including the model type.

    If you want a difference between player and AI models you'll need to create a new type. Or you could just keep altering AIplayer, but let's make a new type for fun.

    example:
    I have a model called Squaddie1 - I want it to be an AI type. First up I sort out my model, animations, and make sure that they are all linked and exec'ed.

    My model is in the correct folder under shapes, and has a squaddie1.cs linking it to it's animations.

    //eg
    
    singleton TSShapeConstructor(squaddie1dts)
    {
       baseShape = "./squaddie1.dts";
    
       sequence0 = "art/shapes/players/animations/arootx.dsq root";
    //.....
    }

    Now, I need to make it an AI type. Back to art/datablocks with a squaddie1.cs for the AI info. Here I'll still be using all the default playerdata, just making sure that my new shape is appearing.

    // Load dts shapes and merge animations
    exec("art/shapes/players/yorks/squaddie1.cs");
    
    datablock PlayerData(squaddie1data : DefaultPlayerData)
    {
       shapeFile = "art/shapes/players/yorks/squaddie1.dts";
       shootingDelay = 540;
    }

    So we have a link to the animations file, and a pointer to the shape to use, which info is again duplicated in the animations file. And it all has the same name. Your directory structure will vary as will the names of models and animations, etc. Don't forget to exec this new file in datablockexec.cs.

    Now, to give it some AI thought process. To scripts/server.
    Make a new file called squaddie1.cs - as it's going to replace everything that demoplayer does, copy that info from AIplayer.cs and then change every instance of demoplayer to squaddie1 (in this case). Don't copy all the AIplayer::functions, you don't want duplicates.

    //eg
    function squaddie1::onReachDestination(%this,%obj)
    {
       // Moves to the next node on the path.
    //....
    }

    Now save new file and exec it from scriptexec.cs.

    When getting an AI to spawn, you'll want to use "squaddie1" as the datablock and not "demoplayer".

    Now that might have answered your Q2 at #15, and also your Q1, but to emphasise,

    server/scripts/AIplayer.cs handles the AI thinking and functions.

    art/datablocks/Aiplayer.cs handles the data properties of the AI (health, speed, etc - and yes, can decide the model type too).

    As for how you want your AI to spawn, that's rather up to you. And you'd have to modify the AIplayer.cs to cope with it - or just add an addition function detailing your spawn and alter the "think" function where it (might - can't remember) check to see if it has spawned or not. That way you could spawn via script fired by trigger or console.

    //caution psuedocode your mileage may vary without lots of editing
    function AIPlayer::dospawn(%name, %aitype, %spawnPoint)
    {
    	if(isObject(%spawnPoint))
    	{
    
              %player = new AIPlayer(%name) {
               dataBlock = %aitype;
               shootingDelay = 540;
    	};
      
      MissionCleanup.add(%player);
    
      %player.setShapeName(%name);
      %player.setTransform(%spawnPoint.gettransform());
    
    	%player.init();
    
    //%player.schedule(%startup, "think");
    
      return %player;
    
    			}
    			else
    			{
    			echo("not a legit spawnpoint - do bugger all");
    			}
    
    }
    
    
    }

    Anyhow, that's a rough guide
    #20
    10/28/2009 (10:11 pm)
    You are indeed THE MAN Steve...I knew I liked you the first time I laid eyes on your coffee cup...lol

    I'm still a bit fuzzy on this though...
    datablock PlayerData(squaddie1data : DefaultPlayerData)

    datablock PlayerData = what? - where does PlayerData come from?

    DefaultPlayerData = what? - where does that come from and what is it calling?

    What if I want squaddie to use his own PlayerData? Is there a time I might want him too? He's a monster afterall not a player (well, the girls say he's a player but that just makes him blush)
    What limitations am I accepting using PlayerData and DefaultPlayerData instead of some unique values? What is entailed to make unique values?

    This particular monster has a weapon that he throws too...I have to try to figure out how to make that work. Any examples you've seen? So far he runs around on a path I set and stops to fight and he's carrying his 'bomb' but he can't throw it. He has an animation called attack2 that makes him look like he's throwing but I don't even know where to trigger that. So atm, he just runs after you smiling an evil grin and twitching his eyebrows...scary, but not deadly...
    Page «Previous 1 2