Game Development Community

AI needs to use seperate mesh from main player

by Dennis in 3D · in Technical Issues · 12/21/2007 (9:49 am) · 3 replies

Hello I need to have a seperate mesh for my AI and Seperate mesh for my Playable character. I have not seen any way to implement a AI character without using the main player mesh.

Is there any way to do this?

#1
12/21/2007 (10:24 am)
Under aiplayer.cs go to the section that reads

datablock PlayerData(DemoPlayer : PlayerBody)

then go to and copy the entire PlayerData datablock from player.cs and rename PlayerBody to look like this

datablock PlayerData(DemoPlayer)

then change the directory for the mesh

className = Armor;
   shapeFile = "~/data/shapes/player/player.dts"; //<------Change this
   cameraMaxDist = 3;


NOTE:: This will allow your ai to be assigned different variables like run and jump

if you dont want that then copy the line
shapeFile = "~/data/shapes/player/player.dts";
and paste it in
datablock PlayerData(DemoPlayer : PlayerBody)
so that it looks like this
datablock PlayerData(DemoPlayer : PlayerBody)
{
   shapeFile = "~/data/shapes/player/player.dts"; 
   shootingDelay = 2000;
};
#2
12/29/2007 (8:33 am)
It Worked Perfectly, Thanks!!!
#3
12/29/2007 (8:39 am)
Well I got my bot walking around a path using his own animation, now I would like to have him see the main character and attack. He dosen't use a gun, he uses his hands, I think I can figure that out but is there a simple way he can see the character? I have checked the forums and they offer complicated script all involving weapons which causes confusion because I don't need all that.

any suggestions or forums tutorials ideas would be most helpful, below is my code.




datablock PlayerData( MyBot : ZombieBody )
{

};

function MyBot::onReachDestination( %this, %obj )
{
// Moves to the next node on the path.
if( %obj.path !$= "" )
{
if( %obj.currentNode == %obj.targetNode )
%this.onEndOfPath( %obj, %obj.path );
else
%obj.moveToNextNode();
}
else
echo( "MyBot::onReachDestination warning - Path is blank!" );
}

function MyBot::onEndOfPath( %this, %obj, %path )
{
%obj.nextTask();
}

//-----------------------------------------------------------------------------
// AIPlayer static functions
//-----------------------------------------------------------------------------

function AIPlayer::spawn( %name, %spawnPoint )
{
// Create the A.I. driven bot object...
%player = new AIPlayer()
{
dataBlock = MyBot;
path = "";
scale = "1.4 1.4 1.4";
};

MissionCleanup.add( %player );
%player.setShapeName( %name );
%player.setTransform( %spawnPoint );

return %player;
}

function AIPlayer::spawnOnPath( %name, %path )
{
// Spawn a bot and place him on the first node of the path
if( !isObject( %path ) )
{
echo( "AIPlayer::spawnOnPath failed - Bad Path!" );
%this.path = "";
return;
}

%node = %path.getObject(0);
%player = AIPlayer::spawn( %name, %node.getTransform() );

return %player;
}

function AIPlayer::followPath( %this, %path, %node )
{
// Start the bot following a path
%this.stopThread(0);
%this.playThread(0, "walk");
if( !isObject( %path ) )
{
echo( "AIPlayer::followPath failed - Bad Path!" );
%this.path = "";
return;
}

if( %node > %path.getCount() - 1 )
%this.targetNode = %path.getCount() - 1;
else
%this.targetNode = %node;

if( %this.path $= %path )
%this.moveToNode(%this.currentNode);
else
{
%this.path = %path;
%this.moveToNode(0);
}
}

function AIPlayer::moveToNextNode( %this )
{
if( %this.targetNode < 0 || %this.currentNode < %this.targetNode )
{
if( %this.currentNode < %this.path.getCount() - 1 )
%this.moveToNode( %this.currentNode + 1 );
else
%this.moveToNode( 0 );
}
else
{
if( %this.currentNode == 0 )
%this.moveToNode( %this.path.getCount() - 1 );
else
%this.moveToNode( %this.currentNode - 1 );
}
}

function AIPlayer::moveToNode( %this, %index )
{
// Move to the given path node index
%this.currentNode = %index;
%node = %this.path.getObject(%index);
%this.setMoveDestination( %node.getTransform(), %index == %this.targetNode );
}

//-----------------------------------------------------------------------------
// AIManager static functions
//-----------------------------------------------------------------------------

function AIManager::think( %this )
{
if( !isObject( %this.player ) )
%this.player = %this.spawn();

%this.schedule( 500, think );
}

function AIManager::spawn( %this )
{

%bot = AIPlayer::spawnOnPath( "Bot_2", "MissionGroup/myPath" );
%bot.followPath( "MissionGroup/myPath", -1 );

return %bot;
}