Game Development Community

Adding more AI and changing the model

by Srivathsa · in Torque Game Engine · 06/03/2009 (12:12 pm) · 3 replies

in the demo level, i want to replace the AI(kork) with some some other model(.dts). but i want to keep the same model for the player. how do i do this? plus, how do i add some more AI characters and make them move in different paths? i have already created different paths and made my AI move along that. I want some more AI. What do i do?? pls help..

#1
06/03/2009 (5:32 pm)
Inside of AIPlayer.cs is where you'll find the methods that handle the basic spawn on Path implementation. You'll have to extend on it to account for multiple paths and bot types.

The simplest way to create multiple types of AI is to use another datablock for each one. But instead of simply duplicating a lot of the same fields you can make you "new" types derive(inherit) from the original player datablock (the parent).

For example "PlayerData(PlayerBody){}" is the default datablock for the player.

datablock PlayerData(DemoPlayer : PlayerBody)
{
    shapeFile = "~/data/shapes/player/DemolitionsGuy.dts"; // change this to your shape!
    shootingDelay = 2000;
};

datablock PlayerData(GuardPlayer : PlayerBody)
{
    shapeFile = "~/data/shapes/player/GuardGuy.dts"; // change this to your shape!
    maxForwardSpeed = 8;
    maxBackwardSpeed = 6;
    maxSideSpeed = 8;
};

In a derived datablock the new datablock's name that you are describing is located before the colon" : ", and the parent datablock that it inherits it's properties from is located after. You can then specify those fields that should be unique for this datablock type, it will inherit the rest from the PlayerBody datablock.
#2
06/04/2009 (10:45 am)
thanks a lot!! :)
#3
06/05/2009 (10:12 am)
I use the RPGDialog resource by Gonsalves. www.garagegames.com/community/resources/view/3531

Like Michael says, you can just inherit ("copy") the datablock with this line;
datablock PlayerData(GuardPlayer : PlayerBody)

then change the shape file like he shows.

Then using the RPGDialog resource, you can spawn different AI (with their own shape) using this line;
SpawnaiElf("Bob", "201 -743 108");

Look here (post #17):
www.garagegames.com/community/forums/viewthread/75606

Here's the whole spawn function;
function SpawnaiElf(%Name,%spawnPoint)   
{   
 %player = new AiPlayer()   
  {   
      dataBlock = aiElf;   
  };   
  %player.setShapeName(%name);   
   %player.setTransform(%spawnPoint);   
return %player;   
}   
  
  
SpawnaiElf("Bob", "201 -743 108.8 0 0 1 160");

Hope it helps!

Tony