Walk don't run!
by Dreamer · in Torque Game Engine · 05/02/2005 (2:28 pm) · 12 replies
I have written a function that will make an AIPlayer go to random points on the map
Only problem is that they RUN, and they run quick! Short of mofying the datablock to cap the max speed is there something I can do here to limit the run speed or possibly just put them into walk mode?
function AIPlayer::Wander(%this){
//Causes AIPlayer to wander aimlessly
%this.stopThread(0);
%x = getRandom(-2048,2048);
%y = getRandom(-2048,2048);
%point = %x SPC %y;
%z = getTerrainHeight(%point);
%point = %point SPC %z;
%this.setMoveDestination(%point);
}Only problem is that they RUN, and they run quick! Short of mofying the datablock to cap the max speed is there something I can do here to limit the run speed or possibly just put them into walk mode?
#2
Torque/engine/game/aiPlayer.cc:316:ConsoleMethod( AIPlayer, setMoveSpeed, void, 3, 3, "( float speed )"
How does this particular function work? I don't really understand it, it seems to be assigning the return value of getMax and getMin to the mMoveSpeed variable?
But what is the getMax, getMin part of this function doing?
Anyways, thanx for the info.
05/03/2005 (7:42 am)
This one?Torque/engine/game/aiPlayer.cc:316:ConsoleMethod( AIPlayer, setMoveSpeed, void, 3, 3, "( float speed )"
/**
* Sets the speed at which this AI moves
*
* @param speed Speed to move, default player was 10
*/
void AIPlayer::setMoveSpeed( F32 speed )
{
mMoveSpeed = getMax(0.0f, getMin( 1.0f, speed ));
}How does this particular function work? I don't really understand it, it seems to be assigning the return value of getMax and getMin to the mMoveSpeed variable?
But what is the getMax, getMin part of this function doing?
Anyways, thanx for the info.
#3
05/03/2005 (8:55 am)
This is a shot in the dark and not knowing any other details I would say the mMoveSpeed is a percentage of the maximum move speed. So the Min and Max parts are keeping the value between 0.0 and 1.0 or 0 and 100%. If you wanted half the speed you would pass the function 0.5. Could be way off base but that's my best guess.
#4
05/03/2005 (9:03 am)
Hey thats a great idea! I'll try that and get back with ya.
#5
05/03/2005 (9:18 am)
Well it works, but @ 0.5 they are running in slomo :(
#6
I added the following code....
Then edited my other function thusly
Problem is no that if for some reason they do enter water, then they stay there :(
I think it has to do with the raycast, returng the waterblock if they are in it... What I really need to do is check to see if there is a waterblock between where the AI is and where is destination is, to keep him from running through the water.
Any ideas?
05/03/2005 (9:38 am)
Ok so running in Slomo is kinda like walking only it has it's own problems... Namely after about 20-30 minutes all the wandering AI's end up stuck in the water.I added the following code....
function findObject(%client,%searchMasks,%distance,%LOS,%AI){
if(%LOS != 0){
%object = DoRaycast(%client,%distance,%searchMasks,%AI);
if(%object){
return(%object);
}else{
return(0);
}
}else{
%object = DoRadiusSearch(%client,%distance,%searchMasks,%AI);
if(%object){
return(%object);
}else{
return(0);
}
}
}
function DoRaycast(%client,%distance,%searchMasks,%AI)
{
if(%AI){
%player = %client;
}else{
%player = %client.player;
}
echo("We are doing raycast and player ="@%player);
%eye = %player.getEyeVector();
%vec = vectorScale(%eye, %distance);
%startPoint = %player.getEyeTransform();
%endPoint = VectorAdd(%startPoint,%vec);
%object = ContainerRayCast (%startPoint, %endPoint, %searchMasks, %player);
if(%object){
echo( "\c1 /// RayCast Search /// " );
echo("\c1 Object = " SPC %object);
echo("\c1 Object Position = " SPC %object.getPosition());
echo("\c1 Object Id = " SPC %object.getId());
echo("\c1 Object Name = " SPC %object.getName());
echo( "\c1 /// --------------- /// " );
return(%object);
}else{
return(0);
}
}Then edited my other function thusly
function AIPlayer::Wander(%this,%seconds){
//Causes AIPlayer to wander aimlessly
%this.stopThread(0);
%x = getRandom(-2048,2048);
%y = getRandom(-2048,2048);
%point = %x SPC %y;
%z = getTerrainHeight(%point);
%point = %point SPC %z;
%targetMaskHit = findObject(%this,$TypeMasks::WaterObjectType,250,1,1);
if(%targetMaskHit){
%this.schedule(500,Wander,%seconds);
echo("Lets not go for a swim");
return;
}
%this.setMoveDestination(%point);
echo("Changing speed and direction for "@%this.getShapeName());
%this.setMoveSpeed(0.5);
if(%seconds <60)
%seconds = 60;
%this.schedule(1000 * %seconds,Wander,%seconds);
}Problem is no that if for some reason they do enter water, then they stay there :(
I think it has to do with the raycast, returng the waterblock if they are in it... What I really need to do is check to see if there is a waterblock between where the AI is and where is destination is, to keep him from running through the water.
Any ideas?
#7
From where do you call the Wander() function ?
Thanks
05/06/2005 (9:28 am)
I have a basic question... From where do you call the Wander() function ?
Thanks
#8
05/06/2005 (11:44 am)
Right after you spawn the AI %aiplayer.Wander(60), in the server/scripts/game.cs file. IIRC in a starter.fps the function would be at the bottom of OnServerCreated or something like that, you will see a call to create Kork, and give him a crossbow, right after giving him a crossbow, then execute the wander statement.
#9
05/06/2005 (1:49 pm)
The orc is still running.... Do I have to comment some code?
#10
05/06/2005 (4:14 pm)
Oh yeah sorry, just use the AISpawnPlayer method, not the spawnonpath one.
#11
%player = AIPlayer::spawn(%name,%node.getTransform()); in function AIManager::spawn(%this) and comment out :
// %player = AIPlayer::spawnOnPath("Kork","MissionGroup/Paths/Path1");
But now there is no Orc at all... Is there something I did wrong?
05/07/2005 (10:25 am)
I put: %player = AIPlayer::spawn(%name,%node.getTransform()); in function AIManager::spawn(%this) and comment out :
// %player = AIPlayer::spawnOnPath("Kork","MissionGroup/Paths/Path1");
But now there is no Orc at all... Is there something I did wrong?
Associate Kyle Carter