View Single Post
Re: How to do correct movement
Old
  (#2)
SteveC
Member
 
Status: Offline
Posts: 37
Join Date: Jan 2005
Location: UK
Default Re: How to do correct movement - 09-01-2005

To build the CUserCmd I used the following code;

Quote:
// look
if (pClosestEnemy)
{
// look at enemy
Vector vAim=vClosestEnemy-pBaseEnt->EyePosition();
VectorAngles(vAim, mBotCmd.viewangles);
}
else if (tFront.fraction<0.5f)
{
mBotCmd.viewangles.y+=90.0f+((float)rand() / RAND_MAX) * 180.0f; // turn 180 (ish)
}
else if (tLeft.fraction<0.5f)
{
mBotCmd.viewangles.y+=22.5f+((float)rand() / RAND_MAX) * 45.0f; // turn +45 (ish)
}
else if (tRight.fraction<0.5f)
{
mBotCmd.viewangles.y-=22.5f+((float)rand() / RAND_MAX) * 45.0f; // turn -45 (ish)
}
// forward
if (pClosestEnemy)
{
mBotCmd.forwardmove=0.0f; // stop to shoot at enemy
}
else
{
mBotCmd.forwardmove=200.0f;
}
//shoot
if (((float)rand() / RAND_MAX)>0.97)
{
mBotCmd.buttons|=IN_ATTACK;
}
else
{
mBotCmd.buttons&=~IN_ATTACK;;
}
//jump
if (((float)rand() / RAND_MAX)>0.97)
{
mBotCmd.buttons|=IN_JUMP;
}
else
{
mBotCmd.buttons&=~IN_JUMP;
}
// issue the command
pPlayerEnt->ProcessUsercmds(&mBotCmd,1,1,0,false);
  
Reply With Quote