Bot movement, only one bot showing....
by arteria3d · in Torque Game Engine · 01/02/2005 (2:05 pm) · 32 replies
I have just been going through the tutorials by Kevin Harris of which i am finding very useful.
I have just completed the bot movement tutorial and decided to add an extra bot and make a separete movement path.
For the second bot i made its own datablock, rather than copying the players again - this was done because of the problem i am about to explain.
When i run the program, the second bot i made is placed on screen and walks around, but i cannot see my first one? which worked fine earlier.
I then went to Game.CS, and swapped around in which way BOT1 and BOT2 loads. So now... i am loading BOT1 second and BOT2 first in the game.cs file. - Now Bot 1 apears, but Bot 2 doesnt!!
After looking in Game.CS again at the following which i needed to add as part of the tutorial:
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();
i noticed that in my second bot.cs that i made - i was making the same call to think() - therefore i thought that because two separate scripts where calling the same function, thats why only one of the bots was showing, and this was dependent on which way around there line was in game.cs
thought of changing the think() function in the second bot to something different, but that didnt work.
I know this may sound confusing - i have tried to explain exactly as is...
How come only one bot is showing, and which one of the two, is dependent on its heirachy in the game.cs file. i.e. If as follows:
exec("./bot1.cs");
exec("./bot2.cs");
bot2 loads and displays on screen
If as follows:
exec("./bot2.cs");
exec("./bot1.cs");
bot1 loads and displays on screen
Thanks
Steve
I have just completed the bot movement tutorial and decided to add an extra bot and make a separete movement path.
For the second bot i made its own datablock, rather than copying the players again - this was done because of the problem i am about to explain.
When i run the program, the second bot i made is placed on screen and walks around, but i cannot see my first one? which worked fine earlier.
I then went to Game.CS, and swapped around in which way BOT1 and BOT2 loads. So now... i am loading BOT1 second and BOT2 first in the game.cs file. - Now Bot 1 apears, but Bot 2 doesnt!!
After looking in Game.CS again at the following which i needed to add as part of the tutorial:
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();
i noticed that in my second bot.cs that i made - i was making the same call to think() - therefore i thought that because two separate scripts where calling the same function, thats why only one of the bots was showing, and this was dependent on which way around there line was in game.cs
thought of changing the think() function in the second bot to something different, but that didnt work.
I know this may sound confusing - i have tried to explain exactly as is...
How come only one bot is showing, and which one of the two, is dependent on its heirachy in the game.cs file. i.e. If as follows:
exec("./bot1.cs");
exec("./bot2.cs");
bot2 loads and displays on screen
If as follows:
exec("./bot2.cs");
exec("./bot1.cs");
bot1 loads and displays on screen
Thanks
Steve
About the author
Owner of uk based Ltd company ArteriaMediaLtd. with a trading name of Arteria3d Website;arteria3d.com
#2
The code is as follows:
for Bot 1:
datablock PlayerData( MyBot : MyPlayer )
{
// TO DO: Add extra stuff here to manage new A.I. functionality...
patrol = true;
attack = false;
};
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();
}
function AIPlayer::spawn( %name, %spawnPoint )
{
// Create the A.I. driven bot object...
%player = new AIPlayer()
{
dataBlock = MyBot;
path = "";
};
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);
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 );
}
function AIManager::think( %this )
{
if( !isObject( %this.player ) )
%this.player = %this.spawn();
%this.schedule( 9500, think );
}
function AIManager::spawn( %this )
{
// Bot_1 simply spawns without a path to follow. Since he has no path to
// follow, he'll simply spawn at the same spot that you do. This means that
// you'll have to move around to see him when the game first starts because
// he'll be right on top of you.
// %bot = AIPlayer::spawn( "Bot_1", pickSpawnPoint() );
// Bot_2 has a path to follow, so we'll help him out by having him spawn
// by the Path's first Path Marker. Once he spawns, he'll begin to follow
// the path using the A.I. helper functions defined here in this file.
%bot = AIPlayer::spawnOnPath( "Bot_2", "MissionGroup/myPath" );
%bot.followPath( "MissionGroup/myPath", -1 );
return %bot;'
}
01/02/2005 (3:34 pm)
Yes a little repetitive!!! Cos i was trying to get over the problem exactly as was - probs confused you more!! Thanks for the interest in my problem.The code is as follows:
for Bot 1:
datablock PlayerData( MyBot : MyPlayer )
{
// TO DO: Add extra stuff here to manage new A.I. functionality...
patrol = true;
attack = false;
};
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();
}
function AIPlayer::spawn( %name, %spawnPoint )
{
// Create the A.I. driven bot object...
%player = new AIPlayer()
{
dataBlock = MyBot;
path = "";
};
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);
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 );
}
function AIManager::think( %this )
{
if( !isObject( %this.player ) )
%this.player = %this.spawn();
%this.schedule( 9500, think );
}
function AIManager::spawn( %this )
{
// Bot_1 simply spawns without a path to follow. Since he has no path to
// follow, he'll simply spawn at the same spot that you do. This means that
// you'll have to move around to see him when the game first starts because
// he'll be right on top of you.
// %bot = AIPlayer::spawn( "Bot_1", pickSpawnPoint() );
// Bot_2 has a path to follow, so we'll help him out by having him spawn
// by the Path's first Path Marker. Once he spawns, he'll begin to follow
// the path using the A.I. helper functions defined here in this file.
%bot = AIPlayer::spawnOnPath( "Bot_2", "MissionGroup/myPath" );
%bot.followPath( "MissionGroup/myPath", -1 );
return %bot;'
}
#3
exec("~/data/shapes/player/boty.cs");
datablock PlayerData( myboty )
{
emap = true;
shapeFile = "~/data/shapes/player/player.dts";
cmdCategory = "Clients";
function MyBoty::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 MyBoty::onEndOfPath( %this, %obj, %path )
{
%obj.nextTask();
}
//-----------------------------------------------------------------------------
// AIPlayer static functions
//-----------------------------------------------------------------------------
function AIPlayer::spawn( %name, %spawnPoint )
{
// Create the A.I. driven bot object...
%player_two = new AIPlayer()
{
dataBlock = MyBoty;
path = "";
};
MissionCleanup.add( %player_two );
%player_two.setShapeName( %name );
%player_two.setTransform( %spawnPoint );
return %player_two;
}
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_two = AIPlayer::spawn( %name, %node.getTransform() );
return %player_two;
}
function AIPlayer::followPath( %this, %path, %node )
{
// Start the bot following a path
%this.stopThread(0);
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 );
}
function AIManager::think( %this )
{
if( !isObject( %this.player_two ) )
%this.player_two = %this.spawn();
%this.schedule( 1500, think );
}
function AIManager::spawn( %this )
{
%bot_two = AIPlayer::spawnOnPath( "Bot_3", "MissionGroup/alien_path" );
%bot_two.followPath( "MissionGroup/alien_path", -1 );
return %bot_two;
}
and now the snippet from game.cs:
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.thinky();
// Start the game timer
if ($Game::Duration)
$Game::Schedule = schedule($Game::Duration * 1000, 0, "onGameDurationEnd" );
$Game::Running = true;
}
function endGame()
{
if (!$Game::Running) {
error("endGame: No game running!");
return;
}
// Stop any game timers
cancel($Game::Schedule);
AIManager.delete();
Thanks
Steve
01/02/2005 (3:34 pm)
For Bot 2 (i actually named this Boty!):exec("~/data/shapes/player/boty.cs");
datablock PlayerData( myboty )
{
emap = true;
shapeFile = "~/data/shapes/player/player.dts";
cmdCategory = "Clients";
function MyBoty::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 MyBoty::onEndOfPath( %this, %obj, %path )
{
%obj.nextTask();
}
//-----------------------------------------------------------------------------
// AIPlayer static functions
//-----------------------------------------------------------------------------
function AIPlayer::spawn( %name, %spawnPoint )
{
// Create the A.I. driven bot object...
%player_two = new AIPlayer()
{
dataBlock = MyBoty;
path = "";
};
MissionCleanup.add( %player_two );
%player_two.setShapeName( %name );
%player_two.setTransform( %spawnPoint );
return %player_two;
}
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_two = AIPlayer::spawn( %name, %node.getTransform() );
return %player_two;
}
function AIPlayer::followPath( %this, %path, %node )
{
// Start the bot following a path
%this.stopThread(0);
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 );
}
function AIManager::think( %this )
{
if( !isObject( %this.player_two ) )
%this.player_two = %this.spawn();
%this.schedule( 1500, think );
}
function AIManager::spawn( %this )
{
%bot_two = AIPlayer::spawnOnPath( "Bot_3", "MissionGroup/alien_path" );
%bot_two.followPath( "MissionGroup/alien_path", -1 );
return %bot_two;
}
and now the snippet from game.cs:
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.thinky();
// Start the game timer
if ($Game::Duration)
$Game::Schedule = schedule($Game::Duration * 1000, 0, "onGameDurationEnd" );
$Game::Running = true;
}
function endGame()
{
if (!$Game::Running) {
error("endGame: No game running!");
return;
}
// Stop any game timers
cancel($Game::Schedule);
AIManager.delete();
Thanks
Steve
#4
so... try this.
function AIManager::spawn(%this)
{
//player2
%player = AIPlayer::spawnOnPath("Glorp","MissionGroup/Paths/Path2");
%player.followPath("MissionGroup/Paths/Path2",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,100000);
//player1
%player = AIPlayer::spawnOnPath("Mlok","MissionGroup/Paths/Path1");
%player.followPath("MissionGroup/Paths/Path1",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,100000);
return %player;
}
That should be all you need then. I would assume that you don't have a weapon called crossbow so you can comment out the.
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,100000);
You can delete the seccone bot script and start on a new bot file. You wil need to change the path names and mebe directorys but that should be all that I can think of. If you don't understand just say so.
Max
01/02/2005 (5:38 pm)
There really is no need to have two script files to get two bots to spawn... They are to ezactly the same path folowing bots if I am correct...so... try this.
function AIManager::spawn(%this)
{
//player2
%player = AIPlayer::spawnOnPath("Glorp","MissionGroup/Paths/Path2");
%player.followPath("MissionGroup/Paths/Path2",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,100000);
//player1
%player = AIPlayer::spawnOnPath("Mlok","MissionGroup/Paths/Path1");
%player.followPath("MissionGroup/Paths/Path1",-1);
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,100000);
return %player;
}
That should be all you need then. I would assume that you don't have a weapon called crossbow so you can comment out the.
%player.mountImage(CrossbowImage,0);
%player.setInventory(CrossbowAmmo,100000);
You can delete the seccone bot script and start on a new bot file. You wil need to change the path names and mebe directorys but that should be all that I can think of. If you don't understand just say so.
Max
#5
So for the above, in the one script, would i still need to load two sep bots - or rather make two bots that share the datablock of the player?/
Also i have been searching for more advanced bot stuff, to include stuff like them pausing for a while when the get to one of the markers - but i cant find anything - how would i do this.
Thanks
Steve
01/03/2005 (7:27 am)
Hi Thomas,So for the above, in the one script, would i still need to load two sep bots - or rather make two bots that share the datablock of the player?/
Also i have been searching for more advanced bot stuff, to include stuff like them pausing for a while when the get to one of the markers - but i cant find anything - how would i do this.
Thanks
Steve
#6
Looking at the code again the way u have combined both bots into the one script - i understand that, but.... i see no indication in either player1/or player2 that actualy refers to the [revioous created datablock for the bot... or am i missing something?
01/03/2005 (12:07 pm)
Thomas, Looking at the code again the way u have combined both bots into the one script - i understand that, but.... i see no indication in either player1/or player2 that actualy refers to the [revioous created datablock for the bot... or am i missing something?
#7
No need to call me Thomas just call me Max a lot of the people here do that :P.
The seccond bot script can be just deleted there is no need for it at all. I might be missing something but I don't know. I think that all you should have to do is replace the AIManager::spawn function I had make sure there are paths for them and the likes. My one question though is are the bots the same same body same path folowing script? Oh, and on the more advanced stuff you were asking about like "them pausing for a while when the get to one of the markers" we'll get to that after we get this sorted out.
I hope I'm not beein too confuzing, Max
01/03/2005 (1:18 pm)
Hey again,No need to call me Thomas just call me Max a lot of the people here do that :P.
The seccond bot script can be just deleted there is no need for it at all. I might be missing something but I don't know. I think that all you should have to do is replace the AIManager::spawn function I had make sure there are paths for them and the likes. My one question though is are the bots the same same body same path folowing script? Oh, and on the more advanced stuff you were asking about like "them pausing for a while when the get to one of the markers" we'll get to that after we get this sorted out.
I hope I'm not beein too confuzing, Max
#8
Max
01/03/2005 (1:19 pm)
If you really can't get this working I'll try it here and send you a file. But please try and figure it out on yur own first for you will not learn from this at all :P.Max
#9
basically i have my two separate paths on the terrain for this example
Bot 1 should follow Path1
and Bot 2 should follow Path2
The ai shape again for this example is the same, but in my game, it would be a different character.
My question, is because they are two separate bots - surely the bot.cs file has to contain two separate datablocks and loads for each of the two ai:players?
Thanks for helping me again Max. I find torque frustrating, as i have the ability to learn, but although there are loads of resources, they arnt specific some times to stuff like ai... etc
01/03/2005 (1:25 pm)
I implemented the changes - but no bots apeared this time..basically i have my two separate paths on the terrain for this example
Bot 1 should follow Path1
and Bot 2 should follow Path2
The ai shape again for this example is the same, but in my game, it would be a different character.
My question, is because they are two separate bots - surely the bot.cs file has to contain two separate datablocks and loads for each of the two ai:players?
Thanks for helping me again Max. I find torque frustrating, as i have the ability to learn, but although there are loads of resources, they arnt specific some times to stuff like ai... etc
#10
Max :)
01/03/2005 (2:26 pm)
I shall post soon I'm going to test this out so I can help you out tith all of this, may I ask what sort of game you're making? Or is that confadencial? :PMax :)
#11
01/03/2005 (2:30 pm)
The scene starts on a deserted tropical island, similar in vein to farcry... i would post u a screenshot, but i dont have a web site to upload it too... i will mail one to your addy...
#12
Max
01/03/2005 (3:51 pm)
I've sent the file you should need with the changes and more instructions if you need them. If anyone here needs help witth the subject just e-mail me and I shall send you the file.Max
#13
You had this wrong
In your Game.cs you have
Should look like this:
And for the First Bot you used:
If your bots are going to behave the same you should be using
the same datablocks like Max showed you.
Lemme know if you're having problems...
01/04/2005 (12:16 am)
Hmmm....You had this wrong
In your Game.cs you have
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.thinky();Should look like this:
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();
AIManager.thinky();And for the First Bot you used:
datablock PlayerData( MyBot : MyPlayer )and the second:
datablock PlayerData( myboty )See the Diff?
If your bots are going to behave the same you should be using
the same datablocks like Max showed you.
Lemme know if you're having problems...
#14
Max
01/04/2005 (6:16 am)
I've sent him a file but thanks anyway for that Burning. I forgot about the AIManager in game.cs :P. I have to tell him to fix that too. I havn't goten a responce to whethier the file works or not but we shall see.Max
#16
01/04/2005 (12:31 pm)
Max, just added ur script and made the change in game.cs - nothing shows up on screen?
#17
%bot = AIPlayer::spawnOnPath( "Bot_1", "MissionGroup/myPath" );
%bot.followPath( "MissionGroup/myPath/Path1", -1 );
//Bot2
%bot = AIPlayer::spawnOnPath( "Bot_2", "MissionGroup/alienpath" );
%bot.followPath( "MissionGroup/myPath2/Path2", -1 );
Wouldnt the fact that we use the same var %bot for both of them means only one will show. Dont we need to use a diff name like %bot_2?
01/04/2005 (12:34 pm)
I noticed these two lines duplicated, but mentioning a diff bot:%bot = AIPlayer::spawnOnPath( "Bot_1", "MissionGroup/myPath" );
%bot.followPath( "MissionGroup/myPath/Path1", -1 );
//Bot2
%bot = AIPlayer::spawnOnPath( "Bot_2", "MissionGroup/alienpath" );
%bot.followPath( "MissionGroup/myPath2/Path2", -1 );
Wouldnt the fact that we use the same var %bot for both of them means only one will show. Dont we need to use a diff name like %bot_2?
#18
//Bot2
%bot = AIPlayer::spawnOnPath( "Bot_2", "MissionGroup/alienpath" );
%bot.followPath( "MissionGroup/myPath2/Path2", -1 );
the %bot = AIPlayer::spawnOnPath( "Bot_2", "MissionGroup/alienpath" ); "MissionGroup/alienpath" should match the bottom "MissionGroup/myPath2/Path2" for the bot to be able to find the marker. Comprende? Same problem with the first one.
Oh, and for the seccond question both bots are using the same datablock there is no need to have two datablocks one for each bot, it's like how one var is defined but in 30 other places use it withought having to define it again...
Max
01/04/2005 (1:26 pm)
Um... steve I don't think that yur understanding at the moment, no offence. Here it's perdy simple at the moment the paths are not beeing defined correctly for which marker to spawn on. Here, for example//Bot2
%bot = AIPlayer::spawnOnPath( "Bot_2", "MissionGroup/alienpath" );
%bot.followPath( "MissionGroup/myPath2/Path2", -1 );
the %bot = AIPlayer::spawnOnPath( "Bot_2", "MissionGroup/alienpath" ); "MissionGroup/alienpath" should match the bottom "MissionGroup/myPath2/Path2" for the bot to be able to find the marker. Comprende? Same problem with the first one.
Oh, and for the seccond question both bots are using the same datablock there is no need to have two datablocks one for each bot, it's like how one var is defined but in 30 other places use it withought having to define it again...
Max
#20
//-----------------------------------------------------------------------------
// To create a Bot or A.I. driven player, we'll simply create a new PlayerData
// datablock called "MyBOT" which derives all of its functionality from the
// "MyPlayer" datablock. This way our Bot starts off being just like any human
// player. The difference is, our Bot will need a few extra methods so it can
// think for it self.
//-----------------------------------------------------------------------------
datablock PlayerData( MyBot : MyPlayer )
{
// TO DO: Add extra stuff here to manage new A.I. functionality...
patrol = true;
attack = false;
};
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 = "";
};
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);
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_2 has a path to follow, so we'll help him out by having him spawn
// by the Path's first Path Marker. Once he spawns, he'll begin to follow
// the path using the A.I. helper functions defined here in this file.
%bot = AIPlayer::spawnOnPath( "Bot_1", "MissionGroup/mypath" );
%bot.followPath( "MissionGroup/mypath", -1 );
//Bot2
//%bot = AIPlayer::spawnOnPath( "Bot_2", "MissionGroup/myPath2/Path2/path" );
//%bot.followPath( "MissionGroup/myPath2/Path2", -1 );
return %bot;
}
01/04/2005 (2:59 pm)
K, i have the following script in, but no bot?//-----------------------------------------------------------------------------
// To create a Bot or A.I. driven player, we'll simply create a new PlayerData
// datablock called "MyBOT" which derives all of its functionality from the
// "MyPlayer" datablock. This way our Bot starts off being just like any human
// player. The difference is, our Bot will need a few extra methods so it can
// think for it self.
//-----------------------------------------------------------------------------
datablock PlayerData( MyBot : MyPlayer )
{
// TO DO: Add extra stuff here to manage new A.I. functionality...
patrol = true;
attack = false;
};
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 = "";
};
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);
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_2 has a path to follow, so we'll help him out by having him spawn
// by the Path's first Path Marker. Once he spawns, he'll begin to follow
// the path using the A.I. helper functions defined here in this file.
%bot = AIPlayer::spawnOnPath( "Bot_1", "MissionGroup/mypath" );
%bot.followPath( "MissionGroup/mypath", -1 );
//Bot2
//%bot = AIPlayer::spawnOnPath( "Bot_2", "MissionGroup/myPath2/Path2/path" );
//%bot.followPath( "MissionGroup/myPath2/Path2", -1 );
return %bot;
}
Torque Owner Max Thomas
Do tell, I'me quite good with problems like this.
Sounds fairly easy at the moment but we shall see, Max