It took a bit of fiddling , but i got it working, so here a little tutorial to get it working for you too (based on botmans template), its not
completely step by step, but it has lots of code snippets.
first, make sure the viewangles get updated by WriteUserCmd in the hpb_bot2_usercmd.x file:
Code:
// THIS IS OLD....
// buf->WriteOneBit( 0 ); // viewangles[0]
// buf->WriteOneBit( 0 ); // viewangles[1]
// buf->WriteOneBit( 0 ); // viewangles[2]
// Viewangles - THIS IS NEW
buf->WriteOneBit( 1 );
buf->WriteBitAngle( cmd->viewangles[ 0 ], 16 );
buf->WriteOneBit( 1 );
buf->WriteBitAngle( cmd->viewangles[ 1 ], 16 );
buf->WriteOneBit( 1 );
buf->WriteBitAngle( cmd->viewangles[ 2 ], 8 );
ok, that will make life a bit more easier
So, first we need a vector in the bot_t so we get our bot moving to that vector constantly. Since the usercmd calls them viewangles (which is NOT correct) , i call it vViewVector.
Code:
typedef struct
{
edict_t* edict;
float fCreateTime; // time bot was created
float fJoinTime; // time when bot should do stuff to join the game (select team, etc)
int iTeam; // the time the bot should join
// FIXME: make it also change when team is forced to another
// so it can be used for knowing which team ur on.
Vector vViewVector;
} bot_t;
// AND in CreateBot
// STEFAN:
pBot->vViewVector = Vector(0,0,0);
Ok, so now we have the viewvector, we need a function to calculate the correct angles to get them in the usercommand... this function is called VectorAngles, and is located in mathlib.* (in public/) , though you cannot use them, they give compile errors which i was not able to fix, so what i did, i ripped it and removed the FastSqrt , replaced it with the (slow)/normal sqrt, and wham we got our own function. So copy this piece of code at the TOP (above the BotRunPlayerMove function):
Code:
//-----------------------------------------------------------------------------
// Forward direction vector -> Euler angles
//-----------------------------------------------------------------------------
// COPIED FROM MATHLIB.CPP - STEFAN
void UTIL_VectorAngles( const Vector& forward, QAngle &angles )
{
// Assert( s_bMathlibInitialized );
float tmp, yaw, pitch;
if (forward[1] == 0 && forward[0] == 0)
{
yaw = 0;
if (forward[2] > 0)
pitch = 270;
else
pitch = 90;
}
else
{
yaw = (atan2(forward[1], forward[0]) * 180 / M_PI);
if (yaw < 0)
yaw += 360;
// STEFAN: use normal sqrt
tmp = sqrt (forward[0]*forward[0] + forward[1]*forward[1]);
pitch = (atan2(-forward[2], tmp) * 180 / M_PI);
if (pitch < 0)
pitch += 360;
}
angles[0] = pitch;
angles[1] = yaw;
angles[2] = 0;
}
go to the BotRunPlayerMove function that botman created; and get this before the processusercmd function:
Code:
if (pBot->vViewVector != Vector(0,0,0))
{
UTIL_VectorAngles( pBot->vViewVector, cmd.viewangles );
// clamp the pitch and yaw (as seen in the sdk)
if (cmd.viewangles[0] > 180)
cmd.viewangles[0] -= 360;
if (cmd.viewangles[1] > 180)
cmd.viewangles[1] -= 360;
}
now, to get a bot going where you want it to go, lets say you have vector vDir, you have to do this:
Code:
Vector botVec=Vector(0,0,0);
gameclients->ClientEarPosition( pPlayerEdict, &botVec );
vDir = vDir - botVec;
pBot->vViewVector = vDir; // ugly hack to set viewdir
so:
1. get the bot vector itself
2. substract your vector with the botvector
3. and finally set vViewVector to vDir
* EDIT:
Let me know if it does , or does not, work for you. I could have forgotten something.
NOTE:
THe bots do not LOOK at the direction, they MOVE at the direction, given the forward speed of the usercmd. (there is no sidespeed set, etc).
I am still looking for a proper 'looking' function.