.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Bot Coding
General Bot Coding See what a pain it is to get those little mechs shooting around

Reply
 
Thread Tools
for cheeseh
Old
  (#1)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default for cheeseh - 13-04-2004

Hi cheesy,

The link to RCBot forum below is broken so I have to post here...

Code:
void CBot :: ChangeAngles ( float *fSpeed, float *fIdeal, float *fCurrent, float *fUpdate )
{
   float fCurrent180;  // current +/- 180 degrees
   float fDiff;

   // turn from the current v_angle yaw to the ideal_yaw by selecting
   // the quickest way to turn to face that direction
   
   // find the difference in the current and ideal angle
   fDiff = abs(*fCurrent - *fIdeal);

   // check if the bot is already facing the ideal_yaw direction...
   if (fDiff <= 0.1)
   {
	*fSpeed = fDiff;

	  return;  // return number of degrees turned
   }

   // check if difference is less than the max degrees per turn
   if (fDiff < *fSpeed)
	  *fSpeed = fDiff;  // just need to turn a little bit (less than max)

   // here we have four cases, both angle positive, one positive and
   // the other negative, one negative and the other positive, or
   // both negative.  handle each case separately...

   if ((*fCurrent >= 0) && (*fIdeal >= 0))  // both positive
   {
	  if (*fCurrent > *fIdeal)
		 *fCurrent -= *fSpeed;
	  else
		 *fCurrent += *fSpeed;
   }
   else if ((*fCurrent >= 0) && (*fIdeal < 0))
   {
	  fCurrent180 = *fCurrent - 180;

	  if (fCurrent180 > *fIdeal)
		 *fCurrent += *fSpeed;
	  else
		 *fCurrent -= *fSpeed;
   }
   else if ((*fCurrent < 0) && (*fIdeal >= 0))
   {
	  fCurrent180 = *fCurrent + 180;
	  if (fCurrent180 > *fIdeal)
		 *fCurrent += *fSpeed;
	  else
		 *fCurrent -= *fSpeed;
   }
   else  // (current < 0) && (ideal < 0)  both negative
   {
	  if (*fCurrent > *fIdeal)
		 *fCurrent -= *fSpeed;
	  else
		 *fCurrent += *fSpeed;
   }

   UTIL_FixFloatAngle(fCurrent);

   *fUpdate = *fCurrent;
}
This code has a minor bug (the abs() should be fabs() - you must have learnt BASIC first). Also the speed is depending on FPS value, which causes RCBot is just too easy to beat (they turn very slow) on my old slow machine.

Here is my new code. I've made the turning FPS independent (basically idea from POD-Bot) and simplified the code a lot (IMHO botman's original code is just too complicated). It should work, though I've only tested it on HLDM.
Code:
void CBot :: ChangeAngles ( float *fSpeed, float *fIdeal, float *fCurrent, float *fUpdate )
{
   // turn from the current v_angle yaw to the ideal_yaw by selecting
   // the quickest way to turn to face that direction

   // find the difference in the current and ideal angle
   float move = *fIdeal - *fCurrent;
   UTIL_FixFloatAngle(&move);

   float fSpeedFactor = 72 * gpGlobals->frametime;
   if (fSpeedFactor < 1.0)
	  fSpeedFactor = 1.0;

   float speed = *fSpeed * fSpeedFactor;

   if (move > 0)
   {
	  if (move > speed)
		 move = speed;
   }
   else
   {
	  if (move < -speed)
		 move = -speed;
   }

   *fCurrent += move;
   UTIL_FixFloatAngle(fCurrent);

   *fUpdate = *fCurrent;
}
Hope this helps... (Also the RCBot TK's quite a lot in HL Teamplay mode, this may be a serious bug, I haven't found how to solve it yet)
  
Reply With Quote
Re: for cheeseh
Old
  (#2)
Cheeseh
[rcbot]
 
Cheeseh's Avatar
 
Status: Offline
Posts: 361
Join Date: Dec 2003
Location: China
Default Re: for cheeseh - 13-04-2004

Thanks for the heads up.. never knew anyone was wanting to really help with my code I haven't looked at my code though for a while, might not again for a month or two really...

the TK thing, The bots will try to move out the way if their view is blocked by anything, that's the best I managed to do. But they don't hold fire even if a team mate is in front of them.'
  
Reply With Quote
Re: for cheeseh
Old
  (#3)
Rick
Council Member
 
Rick's Avatar
 
Status: Offline
Posts: 690
Join Date: Dec 2003
Location: Holland
Default Re: for cheeseh - 13-04-2004

For the team killing an ugly and simple fix might be just tracing a line straight forward and see if it hits an friendly player...if so don't press fire. Though there are still things like grenades
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com