troubles with the new AIPlayer
by Paul Scott · in Torque Game Engine · 10/09/2002 (4:10 pm) · 33 replies
I'm working with the new AIPlayer, and I've run into a few problems that are slightly over my head at this point.
the new AIPlayer is based off of Player. There is a *large* amount of old code that depends on any ai being a game connection, like the old ai was. What is the general opinion on this? Is it better to redo the architecture of the player move generation, spawning, vehicle mounting etc, or is is better to use the old style ai's, based on GameConnection?
Calculating an ai's move can be rather expensive, and frankly does not need to happen every frame. The function getAIMove() currently generates a Move every update. I tried just returning from getAIMove, the bots did not move at all.
I tried saving the xyz,yaw,pitch,roll values from the previous move. The bots sortof danced as they ran, really bizzare to watch.
There's gotta be a way to keep the old vectors, correctly. Anyone know how?
the new AIPlayer is based off of Player. There is a *large* amount of old code that depends on any ai being a game connection, like the old ai was. What is the general opinion on this? Is it better to redo the architecture of the player move generation, spawning, vehicle mounting etc, or is is better to use the old style ai's, based on GameConnection?
Calculating an ai's move can be rather expensive, and frankly does not need to happen every frame. The function getAIMove() currently generates a Move every update. I tried just returning from getAIMove, the bots did not move at all.
I tried saving the xyz,yaw,pitch,roll values from the previous move. The bots sortof danced as they ran, really bizzare to watch.
There's gotta be a way to keep the old vectors, correctly. Anyone know how?
#2
10/10/2002 (2:43 pm)
The AI's position, for the purpose of an AIPlayer does need to be generated every frame, just like a players does. AIPlayer is simply an AI connection to the player object, they play by the same rules pretty much.
#3
I tried zeroing the pitch and yaw of the move last night. It did appear to eliminate the dancing, though the bots had a slight tick. The tick was still present when I ran without skipping move calculations. I'm not certain, but I believe the tick may be caused by my test method of assigning my player at the bot's aim object. I will try moving the bot without setting it's aim tonight.
10/11/2002 (1:20 pm)
Quite true. This is an exploration on the viability of eliminating the AImove calculation process for every frame update by replicating the same move for two or more frames. I tried zeroing the pitch and yaw of the move last night. It did appear to eliminate the dancing, though the bots had a slight tick. The tick was still present when I ran without skipping move calculations. I'm not certain, but I believe the tick may be caused by my test method of assigning my player at the bot's aim object. I will try moving the bot without setting it's aim tonight.
#4
Can someone give a clear picture of what is going on here??
10/19/2002 (3:56 am)
I'm facing the similar problem here.. my bots are "dancing" while they ran.. What I did is just change if (!move && getAIMove(&aiMove))to
if(getAIMove(&aiMove))so that I can apply player movement via mouseclick.
Can someone give a clear picture of what is going on here??
#5
I realized a few days ago that the x, y, z, yaw, pitch, roll values are deltas. To make a move that says "run straight ahead at top speed", do:
y=1, all others = 0
sidestep right, half speed:
x = 0.5, all others = 0
the angles should be 0 to eliminate the dancing.
10/20/2002 (3:19 am)
update: I realized a few days ago that the x, y, z, yaw, pitch, roll values are deltas. To make a move that says "run straight ahead at top speed", do:
y=1, all others = 0
sidestep right, half speed:
x = 0.5, all others = 0
the angles should be 0 to eliminate the dancing.
#6
I've tried the existing methods
but that doesnt do anything.
then I've added another function "startMove()" to the class which simply sets the movestate, but that didnt help either...
any example how to get it to move?? what else do I need to call?
thanx a lot!!
11/07/2002 (11:34 am)
I can't get the new AIPlayer to move at all...I've tried the existing methods
%player.setAimLocation(<some_coordinates_here>); %player.setMoveDestination(<some_coordinates_here>);in AIPlayer::spawnPlayer()
but that doesnt do anything.
then I've added another function "startMove()" to the class which simply sets the movestate, but that didnt help either...
any example how to get it to move?? what else do I need to call?
thanx a lot!!
#7
11/07/2002 (11:41 am)
After setting the destination try %ai.move();
#8
11/07/2002 (11:47 am)
thats the problem... the new AIPlayer doesnt have a "move()" function anymore by default... thats why I've added this:void AIPlayer::startMove()
{
mMoveState = ModeMove;
}
ConsoleMethod( AIPlayer, move, void, 2, 2, "ai.move();" )
{
AIPlayer *ai = static_cast<AIPlayer *>( object );
ai->startMove();
}but that doesnt do anything either... :(
#9
11/07/2002 (11:56 am)
Dammit, just replied and it lost it. Anyway, this format works for me. The line is at the end of the spawn function (before Return %player; but don't think that matters).%player.setMoveDestination("145.0 -180.0 0.0");
#10
11/07/2002 (12:05 pm)
nope, doesnt move at all... just stands there .... and there is no error in the console ...?!
#11
11/07/2002 (12:29 pm)
Do you have a seperate function to spawn the bot? example:function addBot5(%val) {
if(%val)
{
AIPlayer::spawnPlayer("badass");
}
}
moveMap.bind(keyboard, "ctrl 5", addBot5);Is only one bot spawning or are there 2 together? (I had this problem, but it was my own fault). If there's more then one spawning at the same location they can get stuck. Spawning a bot when the player spawns can do that too. I'm not sure what else would be wrong. As soon as the bots I have spawn they run to the move location using that one function.
#12
$myBot = AIPlayer::spawnPlayer();
on the console...
no movement at all... :((
11/07/2002 (12:39 pm)
Yeah, I got functions, and I've tried it in the console... no success... even if it was only one bot...function addBot(%val)
{
if(%val)
{
commandToServer('AddBot');
}
}
$botCounter = 0;
function serverCmdAddBot(%client) {
$bots[$botCounter] = AIPlayer::spawnPlayer("Bot" @ $botCounter);
error("serverCmdAddBot():" SPC "Bot" @ $botCounter);
$bots[$botCounter].setMoveDestination("-245.078003 -167.485001 99.824699");
$bots[$botCounter].move();
$botCounter++;
}and I've also tried$myBot = AIPlayer::spawnPlayer();
on the console...
no movement at all... :((
#13
in the code it sets him to ModeMove for you.
so just calling setMoveDestination will get him to move.
becuase in the getAIMove if he is in ModeMove state
then he will begin the process of movement .. works fine for me
11/07/2002 (1:15 pm)
hmm When you call setMoveDestinationin the code it sets him to ModeMove for you.
so just calling setMoveDestination will get him to move.
becuase in the getAIMove if he is in ModeMove state
then he will begin the process of movement .. works fine for me
#14
11/07/2002 (1:17 pm)
You need to set the speed:if (%me.role $= "Guard")
{
%me.setAimLocation( $cardinalDirection[%me.look]);
%me.getDataBlock().schedule(%spawn.scanperiod, "doScan", %me);
}
else if (%me.role $= "Rover")
{
%me.setMoveSpeed(%spawn.speed);
%me.getDataBlock().setRandomDestination(%me);
%me.getDataBlock().schedule(%spawn.blockperiod, "unBlock", %me);
%me.getDataBlock().schedule(%spawn.scanperiod, "doScan", %me);
}
else if (%me.role $= "Patrol")
{
%me.route = %set;
if ( isObject(BotMarkers) )
{
%dest = BotMarkers.getObject(%me.nextWayPoint).position;
%me.setMoveDestination(%dest);
%me.setMoveSpeed(%spawn.speed);
%me.getDataBlock().schedule(%spawn.scanperiod, "doScan", %me);
}
}
#15
11/07/2002 (1:20 pm)
isnt your spawnPlayer still doing that?
#16
11/07/2002 (1:23 pm)
Yeah, the speed *is* set in the spawning function...function AIPlayer::spawnPlayer(%name)
{
// An example function which creates a new AIPlayer object
// using the the example player datablock.
%player = new AIPlayer() {
dataBlock = LightMaleHumanArmor;
aiPlayer = true;
};
MissionCleanup.add(%player);
%player.setMoveSpeed(1);
%player.setTransform(pickBotSpawnPoint("RedTeamDropPoints"));
%player.setEnergyLevel(60);
%player.setShapeName(%name);
%player.setMoveDestination( "145.0 -180.0 0.0" );
error("%player.getMoveDestination():" SPC %player.getMoveDestination());
}it spawns fine, but doesn't do anything... :/
#17
change the value you give him for speed :)
mine is 0.21 and he still outruns me
add a Con::printf in the getAIMove function
somewhere below the first if
11/07/2002 (1:27 pm)
ok and there are no errors in this script? from console?change the value you give him for speed :)
mine is 0.21 and he still outruns me
add a Con::printf in the getAIMove function
somewhere below the first if
#18
edit: oops, missed a couple posts. Damn work and people bothering me :)
11/07/2002 (1:31 pm)
I'm guessing that that you have the serverCmdAddBot function in the commands.cs file (that's where I had my old bot stuff). You might want to try a function like I have above which is in the default.binds.cs file. That calls the spawn function directly (and add the setMoveDestination line in there of course). I'm not sure but the problem might have something to do with that client reference. The new spawn function example is in the AIPlayer.cs file (which I'm sure you already know). I don't think .move does anything anymore either. It'd be good to just try and get a bot to at least move for ya :)edit: oops, missed a couple posts. Damn work and people bothering me :)
#19
which is faster than the player ..
crazy
11/07/2002 (1:33 pm)
heh .. I checked now and the move speed thing minimum is 1!!which is faster than the player ..
crazy
#20
11/07/2002 (1:36 pm)
1 would be the player speed set in the player datablock the bot uses. You can set it to 0.5 and make the bot slower.
Torque Owner Jeff "tubaguy" Vance